1
|
package eu.dnetlib.client.accountingmonitor;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.*;
|
4
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
5
|
import com.github.gwtbootstrap.client.ui.constants.BackdropType;
|
6
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
7
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
8
|
import com.google.gwt.core.client.GWT;
|
9
|
import com.google.gwt.event.dom.client.ClickEvent;
|
10
|
import com.google.gwt.event.dom.client.ClickHandler;
|
11
|
import com.google.gwt.user.client.Window;
|
12
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
13
|
import com.google.gwt.user.client.ui.FlowPanel;
|
14
|
import com.google.gwt.user.client.ui.HTML;
|
15
|
import com.google.gwt.user.client.ui.IsWidget;
|
16
|
import com.google.gwt.user.client.ui.Widget;
|
17
|
import eu.dnetlib.client.*;
|
18
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityDisplayWidget;
|
19
|
import eu.dnetlib.client.fundingrequest.stepinfo.*;
|
20
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
21
|
import eu.dnetlib.goldoa.domain.Currency;
|
22
|
import eu.dnetlib.goldoa.domain.Request;
|
23
|
import eu.dnetlib.goldoa.domain.RequestInfo;
|
24
|
|
25
|
/**
|
26
|
* Created by stefania on 4/30/15.
|
27
|
*/
|
28
|
public class AccountingRequestInfoElement implements IsWidget {
|
29
|
|
30
|
private FlowPanel requestInfoPanel = new FlowPanel();
|
31
|
|
32
|
private Alert errorLabel = new Alert();
|
33
|
private Alert successLabel = new Alert();
|
34
|
|
35
|
private FlowPanel requestSummaryPanel = new FlowPanel();
|
36
|
private FlowPanel firstDivider = new FlowPanel();
|
37
|
|
38
|
private FlowPanel actionButtons = new FlowPanel();
|
39
|
private Button processing = new Button("Processing");
|
40
|
private Button paid = new Button("Paid");
|
41
|
private Button putOnHold = new Button("Hold");
|
42
|
private Button denied = new Button("Deny");
|
43
|
|
44
|
private FlowPanel editInfoButtons = new FlowPanel();
|
45
|
private Button editBankTransferInfo = new Button("Edit bank transfer info");
|
46
|
|
47
|
private FlowPanel secondDivider = new FlowPanel();
|
48
|
|
49
|
private Form commentsForm = new Form();
|
50
|
private TextArea comments = new TextArea();
|
51
|
|
52
|
private ActionListener actionListener;
|
53
|
|
54
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
55
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
56
|
|
57
|
public AccountingRequestInfoElement(final RequestInfo requestInfo) {
|
58
|
|
59
|
requestInfoPanel.addStyleName("requestInfoPanel");
|
60
|
|
61
|
successLabel.addStyleName("alertLabel");
|
62
|
successLabel.setType(AlertType.SUCCESS);
|
63
|
successLabel.setVisible(false);
|
64
|
successLabel.setClose(false);
|
65
|
|
66
|
errorLabel.addStyleName("alertLabel");
|
67
|
errorLabel.setType(AlertType.ERROR);
|
68
|
errorLabel.setVisible(false);
|
69
|
errorLabel.setClose(false);
|
70
|
|
71
|
requestSummaryPanel.addStyleName("requestDetailedInfoPanel");
|
72
|
|
73
|
if(requestInfo.getResearcher()!=null) {
|
74
|
ResearcherInlineInfo researcherInlineInfo = new ResearcherInlineInfo(requestInfo.getResearcher());
|
75
|
requestSummaryPanel.add(researcherInlineInfo.asWidget());
|
76
|
}
|
77
|
|
78
|
if(requestInfo.getProject()!=null) {
|
79
|
ProjectInlineInfo projectInlineInfo = new ProjectInlineInfo(requestInfo.getProject());
|
80
|
requestSummaryPanel.add(projectInlineInfo.asWidget());
|
81
|
}
|
82
|
|
83
|
if(requestInfo.getPublication()!=null) {
|
84
|
PublicationInlineInfo publicationInlineInfo = new PublicationInlineInfo(requestInfo.getPublication());
|
85
|
requestSummaryPanel.add(publicationInlineInfo.asWidget());
|
86
|
}
|
87
|
|
88
|
float apc = 0;
|
89
|
float discount = 0;
|
90
|
|
91
|
if(requestInfo.getPublication()!=null && requestInfo.getPublication().getJournal()!=null) {
|
92
|
JournalInlineInfo journalInlineInfo = new JournalInlineInfo(requestInfo.getPublication().getJournal());
|
93
|
requestSummaryPanel.add(journalInlineInfo.asWidget());
|
94
|
apc = requestInfo.getPublication().getJournal().getApc();
|
95
|
discount = requestInfo.getPublication().getJournal().getDiscount();
|
96
|
}
|
97
|
|
98
|
if(requestInfo.getPublication()!=null && requestInfo.getPublication().getPublisher()!=null) {
|
99
|
PublisherInlineInfo publisherInlineInfo = new PublisherInlineInfo(requestInfo.getPublication().getPublisher());
|
100
|
requestSummaryPanel.add(publisherInlineInfo.asWidget());
|
101
|
apc = requestInfo.getPublication().getPublisher().getAPC();
|
102
|
discount = requestInfo.getPublication().getPublisher().getDiscount();
|
103
|
}
|
104
|
|
105
|
if(requestInfo.getProjectParticipation()!=null && requestInfo.getFundingRequested()!=null) {
|
106
|
|
107
|
if(!requestInfo.getCurrency().equals(Currency.EUR)) {
|
108
|
|
109
|
final float finalApc = apc;
|
110
|
final float finalDiscount = discount;
|
111
|
dataService.convert(requestInfo.getCurrency(), Currency.EUR, requestInfo.getFundingRequested(), new AsyncCallback<Float>() {
|
112
|
|
113
|
@Override
|
114
|
public void onFailure(Throwable throwable) {
|
115
|
AccountingInlineInfo accountingInlineInfo = new AccountingInlineInfo(new Request(requestInfo), finalApc, finalDiscount, requestInfo.getCurrency(), 0);
|
116
|
requestSummaryPanel.add(accountingInlineInfo.asWidget());
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
public void onSuccess(Float aFloat) {
|
121
|
AccountingInlineInfo accountingInlineInfo = new AccountingInlineInfo(new Request(requestInfo), finalApc, finalDiscount, requestInfo.getCurrency(), aFloat);
|
122
|
requestSummaryPanel.add(accountingInlineInfo.asWidget());
|
123
|
}
|
124
|
});
|
125
|
} else {
|
126
|
AccountingInlineInfo accountingInlineInfo = new AccountingInlineInfo(new Request(requestInfo), apc, discount, requestInfo.getCurrency(), 0);
|
127
|
requestSummaryPanel.add(accountingInlineInfo.asWidget());
|
128
|
}
|
129
|
}
|
130
|
|
131
|
if(requestInfo.getInvoice()!=null) {
|
132
|
InvoiceInlineInfo invoiceInlineInfo = new InvoiceInlineInfo(requestInfo.getInvoice());
|
133
|
requestSummaryPanel.add(invoiceInlineInfo.asWidget());
|
134
|
}
|
135
|
|
136
|
if(requestInfo.getBankAccount()!=null &&
|
137
|
((requestInfo.getBankAccount().getBankName()!=null && !requestInfo.getBankAccount().getBankName().equals(""))
|
138
|
|| (requestInfo.getBankAccount().getBankAddress()!=null && !requestInfo.getBankAccount().getBankAddress().equals(""))
|
139
|
|| (requestInfo.getBankAccount().getAccountHolder()!=null && !requestInfo.getBankAccount().getAccountHolder().equals(""))
|
140
|
|| (requestInfo.getBankAccount().getIban()!=null && !requestInfo.getBankAccount().getIban().equals(""))
|
141
|
|| (requestInfo.getBankAccount().getBankCode()!=null && !requestInfo.getBankAccount().getBankCode().equals("")))) {
|
142
|
BankAccountInlineInfo bankAccountInlineInfo = new BankAccountInlineInfo(requestInfo.getBankAccount());
|
143
|
requestSummaryPanel.add(bankAccountInlineInfo.asWidget());
|
144
|
}
|
145
|
|
146
|
if(requestInfo.getPublisherEmail()!=null) {
|
147
|
PublisherContactInfo publisherContactInfo = new PublisherContactInfo(requestInfo.getPublisherEmail());
|
148
|
requestSummaryPanel.add(publisherContactInfo.asWidget());
|
149
|
}
|
150
|
|
151
|
if (requestInfo.getStatus().equals(Request.RequestStatus.ACCOUNTING_PAID) && requestInfo.getApc_paid()!=null
|
152
|
&& requestInfo.getTransfer_cost()!=null && requestInfo.getDate_paid()!=null) {
|
153
|
BankTransferInlineInfo bankTransferInlineInfo = new BankTransferInlineInfo(requestInfo);
|
154
|
requestSummaryPanel.add(bankTransferInlineInfo.asWidget());
|
155
|
}
|
156
|
|
157
|
commentsForm.setType(FormType.VERTICAL);
|
158
|
commentsForm.add(new FormFieldSet("Add a new comment", comments));
|
159
|
|
160
|
actionButtons.addStyleName("requestInfoActionButtons");
|
161
|
|
162
|
editInfoButtons.addStyleName("requestInfoActionButtons");
|
163
|
|
164
|
processing.addStyleName("requestInfoActionButton");
|
165
|
processing.setType(ButtonType.DEFAULT);
|
166
|
processing.addClickHandler(new ClickHandler() {
|
167
|
@Override
|
168
|
public void onClick(ClickEvent clickEvent) {
|
169
|
|
170
|
errorLabel.setVisible(false);
|
171
|
successLabel.setVisible(false);
|
172
|
|
173
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
174
|
requestInfoPanel.addStyleName("loading");
|
175
|
requestInfoPanel.add(loadingWheel);
|
176
|
|
177
|
String comment = comments.getValue().trim();
|
178
|
if(comment.equals(""))
|
179
|
comment = null;
|
180
|
|
181
|
final String commentText = comment;
|
182
|
dataService.processingRequest(requestInfo.getId(), GoldOAPortal.currentUser.getId(), comment, new AsyncCallback<Void>() {
|
183
|
|
184
|
@Override
|
185
|
public void onFailure(Throwable throwable) {
|
186
|
|
187
|
requestInfoPanel.removeStyleName("loading");
|
188
|
requestInfoPanel.remove(loadingWheel);
|
189
|
|
190
|
errorLabel.setText("Error while processing request's payment.");
|
191
|
errorLabel.setVisible(true);
|
192
|
if (actionListener != null)
|
193
|
actionListener.actionHappened(false, Request.RequestStatus.ACCOUNTING_PROCESSING, commentText);
|
194
|
}
|
195
|
|
196
|
@Override
|
197
|
public void onSuccess(Void aVoid) {
|
198
|
|
199
|
requestInfoPanel.removeStyleName("loading");
|
200
|
requestInfoPanel.remove(loadingWheel);
|
201
|
|
202
|
successLabel.setText("Request's payment processing");
|
203
|
successLabel.setVisible(true);
|
204
|
requestInfoPanel.remove(commentsForm);
|
205
|
requestInfoPanel.remove(actionButtons);
|
206
|
if (actionListener != null)
|
207
|
actionListener.actionHappened(true, Request.RequestStatus.ACCOUNTING_PROCESSING, commentText);
|
208
|
}
|
209
|
});
|
210
|
}
|
211
|
});
|
212
|
actionButtons.add(processing);
|
213
|
|
214
|
paid.addStyleName("requestInfoActionButton");
|
215
|
paid.setType(ButtonType.DEFAULT);
|
216
|
paid.addClickHandler(new ClickHandler() {
|
217
|
@Override
|
218
|
public void onClick(ClickEvent clickEvent) {
|
219
|
|
220
|
errorLabel.setVisible(false);
|
221
|
successLabel.setVisible(false);
|
222
|
|
223
|
String comment = comments.getValue().trim();
|
224
|
if(comment.equals(""))
|
225
|
comment = null;
|
226
|
|
227
|
final String commentText = comment;
|
228
|
|
229
|
final Modal bankTransferInfoModal = new Modal();
|
230
|
|
231
|
bankTransferInfoModal.addStyleName("bankTransferModal");
|
232
|
bankTransferInfoModal.setAnimation(true);
|
233
|
bankTransferInfoModal.setBackdrop(BackdropType.STATIC);
|
234
|
bankTransferInfoModal.setDynamicSafe(true);
|
235
|
|
236
|
BankTransferForm bankTransferForm = new BankTransferForm(requestInfo.getId(), comment, requestInfo.getInvoice(), false);
|
237
|
BankTransferForm.UploadCompleteListener uploadCompleteListener = new BankTransferForm.UploadCompleteListener() {
|
238
|
@Override
|
239
|
public void uploadCompleted(boolean succeeded) {
|
240
|
bankTransferInfoModal.hide();
|
241
|
if(actionListener!=null)
|
242
|
actionListener.actionHappened(true, Request.RequestStatus.ACCOUNTING_PAID, commentText);
|
243
|
}
|
244
|
};
|
245
|
bankTransferForm.setUploadCompleteListener(uploadCompleteListener);
|
246
|
|
247
|
BankTransferForm.CancelListener cancelListener = new BankTransferForm.CancelListener() {
|
248
|
@Override
|
249
|
public void cancel() {
|
250
|
bankTransferInfoModal.hide();
|
251
|
}
|
252
|
};
|
253
|
bankTransferForm.setCancelListener(cancelListener);
|
254
|
|
255
|
bankTransferInfoModal.add(bankTransferForm.asWidget());
|
256
|
bankTransferInfoModal.show();
|
257
|
}
|
258
|
});
|
259
|
actionButtons.add(paid);
|
260
|
|
261
|
putOnHold.addStyleName("requestInfoActionButton");
|
262
|
putOnHold.setType(ButtonType.DEFAULT);
|
263
|
putOnHold.addClickHandler(new ClickHandler() {
|
264
|
@Override
|
265
|
public void onClick(ClickEvent clickEvent) {
|
266
|
|
267
|
errorLabel.setVisible(false);
|
268
|
successLabel.setVisible(false);
|
269
|
|
270
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
271
|
requestInfoPanel.addStyleName("loading");
|
272
|
requestInfoPanel.add(loadingWheel);
|
273
|
|
274
|
String comment = comments.getValue().trim();
|
275
|
if (comment.equals(""))
|
276
|
comment = null;
|
277
|
|
278
|
final String commentText = comment;
|
279
|
dataService.onHoldRequest(requestInfo.getId(), GoldOAPortal.currentUser.getId(), comment, new AsyncCallback<Void>() {
|
280
|
|
281
|
@Override
|
282
|
public void onFailure(Throwable throwable) {
|
283
|
|
284
|
requestInfoPanel.removeStyleName("loading");
|
285
|
requestInfoPanel.remove(loadingWheel);
|
286
|
|
287
|
errorLabel.setText(goldOAConstants.accountingErrorPuttingRequestOnHold());
|
288
|
errorLabel.setVisible(true);
|
289
|
if (actionListener != null)
|
290
|
actionListener.actionHappened(false, Request.RequestStatus.ACCOUNTING_ON_HOLD, commentText);
|
291
|
}
|
292
|
|
293
|
@Override
|
294
|
public void onSuccess(Void aVoid) {
|
295
|
|
296
|
requestInfoPanel.removeStyleName("loading");
|
297
|
requestInfoPanel.remove(loadingWheel);
|
298
|
|
299
|
successLabel.setText(goldOAConstants.accountingSuccessPuttingRequestOnHold());
|
300
|
successLabel.setVisible(true);
|
301
|
requestInfoPanel.remove(commentsForm);
|
302
|
requestInfoPanel.remove(actionButtons);
|
303
|
if (actionListener != null)
|
304
|
actionListener.actionHappened(true, Request.RequestStatus.ACCOUNTING_ON_HOLD, commentText);
|
305
|
}
|
306
|
});
|
307
|
}
|
308
|
});
|
309
|
actionButtons.add(putOnHold);
|
310
|
|
311
|
denied.addStyleName("requestInfoActionButton");
|
312
|
denied.setType(ButtonType.DEFAULT);
|
313
|
denied.addClickHandler(new ClickHandler() {
|
314
|
@Override
|
315
|
public void onClick(ClickEvent clickEvent) {
|
316
|
|
317
|
errorLabel.setVisible(false);
|
318
|
successLabel.setVisible(false);
|
319
|
|
320
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
321
|
requestInfoPanel.addStyleName("loading");
|
322
|
requestInfoPanel.add(loadingWheel);
|
323
|
|
324
|
String comment = comments.getValue().trim();
|
325
|
if(comment.equals(""))
|
326
|
comment = null;
|
327
|
|
328
|
final String commentText = comment;
|
329
|
dataService.deniedRequest(requestInfo.getId(), GoldOAPortal.currentUser.getId(), comment, new AsyncCallback<Void>() {
|
330
|
|
331
|
@Override
|
332
|
public void onFailure(Throwable throwable) {
|
333
|
|
334
|
requestInfoPanel.removeStyleName("loading");
|
335
|
requestInfoPanel.remove(loadingWheel);
|
336
|
|
337
|
errorLabel.setText(goldOAConstants.accountingErrorDenyingRequest());
|
338
|
errorLabel.setVisible(true);
|
339
|
if (actionListener != null)
|
340
|
actionListener.actionHappened(false, Request.RequestStatus.ACCOUNTING_DENIED, commentText);
|
341
|
}
|
342
|
|
343
|
@Override
|
344
|
public void onSuccess(Void aVoid) {
|
345
|
|
346
|
requestInfoPanel.removeStyleName("loading");
|
347
|
requestInfoPanel.remove(loadingWheel);
|
348
|
|
349
|
successLabel.setText(goldOAConstants.accountingSuccessDenyingRequest());
|
350
|
successLabel.setVisible(true);
|
351
|
requestInfoPanel.remove(commentsForm);
|
352
|
requestInfoPanel.remove(actionButtons);
|
353
|
if (actionListener != null)
|
354
|
actionListener.actionHappened(true, Request.RequestStatus.ACCOUNTING_DENIED, commentText);
|
355
|
}
|
356
|
});
|
357
|
}
|
358
|
});
|
359
|
actionButtons.add(denied);
|
360
|
|
361
|
editBankTransferInfo.addStyleName("requestInfoActionButton");
|
362
|
editBankTransferInfo.setType(ButtonType.PRIMARY);
|
363
|
editBankTransferInfo.addClickHandler(new ClickHandler() {
|
364
|
@Override
|
365
|
public void onClick(ClickEvent clickEvent) {
|
366
|
|
367
|
errorLabel.setVisible(false);
|
368
|
successLabel.setVisible(false);
|
369
|
|
370
|
String comment = comments.getValue().trim();
|
371
|
if(comment.equals(""))
|
372
|
comment = null;
|
373
|
|
374
|
final String commentText = comment;
|
375
|
|
376
|
final Modal bankTransferInfoModal = new Modal();
|
377
|
|
378
|
bankTransferInfoModal.addStyleName("bankTransferModal");
|
379
|
bankTransferInfoModal.setAnimation(true);
|
380
|
bankTransferInfoModal.setBackdrop(BackdropType.STATIC);
|
381
|
bankTransferInfoModal.setDynamicSafe(true);
|
382
|
|
383
|
BankTransferForm bankTransferForm = new BankTransferForm(requestInfo.getId(), comment, requestInfo.getInvoice(), true);
|
384
|
BankTransferForm.UploadCompleteListener uploadCompleteListener = new BankTransferForm.UploadCompleteListener() {
|
385
|
@Override
|
386
|
public void uploadCompleted(boolean succeeded) {
|
387
|
bankTransferInfoModal.hide();
|
388
|
if(actionListener!=null)
|
389
|
actionListener.actionHappened(true, Request.RequestStatus.ACCOUNTING_PAID, commentText);
|
390
|
}
|
391
|
};
|
392
|
bankTransferForm.setUploadCompleteListener(uploadCompleteListener);
|
393
|
|
394
|
BankTransferForm.CancelListener cancelListener = new BankTransferForm.CancelListener() {
|
395
|
@Override
|
396
|
public void cancel() {
|
397
|
bankTransferInfoModal.hide();
|
398
|
}
|
399
|
};
|
400
|
bankTransferForm.setCancelListener(cancelListener);
|
401
|
|
402
|
bankTransferInfoModal.add(bankTransferForm.asWidget());
|
403
|
bankTransferInfoModal.show();
|
404
|
}
|
405
|
});
|
406
|
editInfoButtons.add(editBankTransferInfo);
|
407
|
|
408
|
firstDivider.addStyleName("uk-grid-divider");
|
409
|
secondDivider.addStyleName("uk-grid-divider");
|
410
|
|
411
|
EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(requestInfo.getEligibility());
|
412
|
|
413
|
requestInfoPanel.add(successLabel);
|
414
|
requestInfoPanel.add(errorLabel);
|
415
|
requestInfoPanel.add(eligibilityDisplayWidget.asWidget());
|
416
|
requestInfoPanel.add(firstDivider);
|
417
|
requestInfoPanel.add(requestSummaryPanel);
|
418
|
|
419
|
if((requestInfo.getComments()!=null && !requestInfo.getComments().isEmpty())
|
420
|
|| !requestInfo.getStatus().equals(Request.RequestStatus.ACCOUNTING_DENIED)) {
|
421
|
|
422
|
requestInfoPanel.add(secondDivider);
|
423
|
|
424
|
if(requestInfo.getComments()!=null && !requestInfo.getComments().isEmpty()) {
|
425
|
CommentsInfo commentsInfo = new CommentsInfo(requestInfo.getComments());
|
426
|
commentsInfo.addStyleName("requestComments");
|
427
|
requestInfoPanel.add(commentsInfo.asWidget());
|
428
|
}
|
429
|
|
430
|
if(requestInfo.getStatus().equals(Request.RequestStatus.ACCOUNTING_PAID)) {
|
431
|
requestInfoPanel.add(editInfoButtons);
|
432
|
} else if(!requestInfo.getStatus().equals(Request.RequestStatus.ACCOUNTING_DENIED)) {
|
433
|
requestInfoPanel.add(commentsForm);
|
434
|
requestInfoPanel.add(actionButtons);
|
435
|
}
|
436
|
}
|
437
|
}
|
438
|
|
439
|
@Override
|
440
|
public Widget asWidget() {
|
441
|
return requestInfoPanel;
|
442
|
}
|
443
|
|
444
|
public interface ActionListener {
|
445
|
public void actionHappened(boolean succeeded, Request.RequestStatus status, String comments);
|
446
|
}
|
447
|
|
448
|
public void setActionListener(ActionListener actionListener) {
|
449
|
this.actionListener = actionListener;
|
450
|
}
|
451
|
}
|