use of org.projectforge.framework.time.DateTimeFormatter in project projectforge by micromata.
the class EingangsrechnungListPage method exportInvoicesAsXML.
private void exportInvoicesAsXML(final List<EingangsrechnungDO> invoices) {
if (invoices == null || invoices.size() == 0) {
// Nothing to export.
form.addError("validation.error.nothingToExport");
return;
}
this.form.getFeedbackMessages().clear();
final String filename = String.format("transfer-%s.xml", DateHelper.getTimestampAsFilenameSuffix(new Date()));
try {
SEPATransferResult result = this.SEPATransferGenerator.format(invoices);
if (result.isSuccessful() == false) {
if (result.getErrors().isEmpty()) {
// unknown error
log.error("Oups, xml has zero size. Filename: " + filename);
this.form.addError("fibu.rechnung.transferExport.error");
return;
}
List<String> brokenInvoices = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.instance();
// check invoice
for (EingangsrechnungDO invoice : result.getErrors().keySet()) {
if (invoice.getReferenz() != null) {
brokenInvoices.add("[" + invoice.getKreditor() + ", " + invoice.getReferenz() + ", " + formatter.getFormattedDate(invoice.getDatum()) + "]");
} else {
brokenInvoices.add("[" + invoice.getKreditor() + ", " + formatter.getFormattedDate(invoice.getDatum()) + "]");
}
}
String brokenInvoicesStr = String.join("; ", brokenInvoices);
this.form.addError("fibu.rechnung.transferExport.error.entries", brokenInvoicesStr);
return;
}
DownloadUtils.setDownloadTarget(result.getXml(), filename);
} catch (UserException e) {
this.form.addError("error", e.getParams()[0]);
}
}
Aggregations