Line 73... |
Line 73... |
73 |
import java.util.Map;
|
73 |
import java.util.Map;
|
74 |
import java.util.Map.Entry;
|
74 |
import java.util.Map.Entry;
|
75 |
import java.util.NavigableMap;
|
75 |
import java.util.NavigableMap;
|
76 |
import java.util.Set;
|
76 |
import java.util.Set;
|
77 |
import java.util.TreeMap;
|
77 |
import java.util.TreeMap;
|
- |
|
78 |
import java.util.concurrent.ExecutionException;
|
78 |
import java.util.prefs.Preferences;
|
79 |
import java.util.prefs.Preferences;
|
79 |
|
80 |
|
80 |
import javax.swing.AbstractAction;
|
81 |
import javax.swing.AbstractAction;
|
81 |
import javax.swing.JFileChooser;
|
82 |
import javax.swing.JFileChooser;
|
- |
|
83 |
import javax.swing.SwingWorker;
|
82 |
|
84 |
|
83 |
import org.jdom2.Document;
|
85 |
import org.jdom2.Document;
|
84 |
import org.jdom2.Element;
|
86 |
import org.jdom2.Element;
|
85 |
import org.jdom2.Namespace;
|
87 |
import org.jdom2.Namespace;
|
86 |
|
88 |
|
Line 111... |
Line 113... |
111 |
this.prefsPath = conf.getAppID() + '/' + this.getCode().replace('.', '/');
|
113 |
this.prefsPath = conf.getAppID() + '/' + this.getCode().replace('.', '/');
|
112 |
this.getRowActions().add(new RowAction.PredicateRowAction(new AbstractAction("Exporter…") {
|
114 |
this.getRowActions().add(new RowAction.PredicateRowAction(new AbstractAction("Exporter…") {
|
113 |
@Override
|
115 |
@Override
|
114 |
public void actionPerformed(ActionEvent e) {
|
116 |
public void actionPerformed(ActionEvent e) {
|
115 |
final IListe l = IListe.get(e);
|
117 |
final IListe l = IListe.get(e);
|
116 |
// XML field values are quite large so only fetch them when needed
|
- |
|
117 |
final SQLTable t = l.getSource().getPrimaryTable();
|
118 |
final SQLTable t = l.getSource().getPrimaryTable();
|
- |
|
119 |
final Set<Integer> userSelectedIDs = l.getSelection().getUserSelectedIDs();
|
- |
|
120 |
new SwingWorker<List<SQLRow>, Void>() {
|
- |
|
121 |
@Override
|
- |
|
122 |
protected List<SQLRow> doInBackground() throws Exception {
|
118 |
final SQLSelect sel = new SQLSelect().addSelectStar(t);
|
123 |
final SQLSelect sel = new SQLSelect().addSelectStar(t);
|
- |
|
124 |
// XML field values are quite large so only fetch them when needed
|
119 |
sel.setWhere(new Where(t.getKey(), l.getSelection().getUserSelectedIDs()));
|
125 |
sel.setWhere(new Where(t.getKey(), userSelectedIDs));
|
120 |
exportXML(l, SQLRowListRSH.execute(sel));
|
126 |
return SQLRowListRSH.execute(sel);
|
- |
|
127 |
}
|
- |
|
128 |
|
- |
|
129 |
@Override
|
- |
|
130 |
protected void done() {
|
- |
|
131 |
List<SQLRow> execute;
|
- |
|
132 |
try {
|
- |
|
133 |
execute = get();
|
- |
|
134 |
exportXML(l, execute);
|
- |
|
135 |
} catch (InterruptedException | ExecutionException e) {
|
- |
|
136 |
e.printStackTrace();
|
- |
|
137 |
}
|
- |
|
138 |
|
- |
|
139 |
}
|
- |
|
140 |
}.execute();
|
121 |
}
|
141 |
}
|
122 |
}, true, false).setPredicate(IListeEvent.getNonEmptySelectionPredicate()));
|
142 |
}, true, false).setPredicate(IListeEvent.getNonEmptySelectionPredicate()));
|
123 |
this.rowSociété = conf.getRowSociete();
|
143 |
this.rowSociété = conf.getRowSociete();
|
124 |
this.dbPrefs = new SQLPreferences(conf.getRootSociete());
|
144 |
this.dbPrefs = new SQLPreferences(conf.getRootSociete());
|
125 |
this.fieldTranslator = conf.getTranslator();
|
145 |
this.fieldTranslator = conf.getTranslator();
|
Line 194... |
Line 214... |
194 |
}
|
214 |
}
|
195 |
}
|
215 |
}
|
196 |
}
|
216 |
}
|
197 |
|
217 |
|
198 |
protected static BigDecimal getInvoiceAmount(final SQLRowValues invoice) {
|
218 |
protected static BigDecimal getInvoiceAmount(final SQLRowValues invoice) {
|
- |
|
219 |
if (invoice.getTable().getName().equals("SAISIE_VENTE_FACTURE")) {
|
199 |
return BigDecimal.valueOf(invoice.getLong("NET_A_PAYER")).movePointLeft(2);
|
220 |
return BigDecimal.valueOf(invoice.getLong("NET_A_PAYER")).movePointLeft(2);
|
- |
|
221 |
} else {
|
- |
|
222 |
return BigDecimal.valueOf(invoice.getLong("MONTANT")).movePointLeft(2);
|
- |
|
223 |
}
|
200 |
}
|
224 |
}
|
201 |
|
225 |
|
202 |
static private final class InvoiceElem extends Tuple2<SQLRowValues, Element> {
|
226 |
static private final class InvoiceElem extends Tuple2<SQLRowValues, Element> {
|
203 |
protected InvoiceElem(SQLRowValues a, Element b) {
|
227 |
protected InvoiceElem(SQLRowValues a, Element b) {
|
204 |
super(a, b);
|
228 |
super(a, b);
|
Line 294... |
Line 318... |
294 |
this.sum = this.sum.add(getInvoiceAmount(invoice));
|
318 |
this.sum = this.sum.add(getInvoiceAmount(invoice));
|
295 |
|
319 |
|
296 |
return IgnoreReason.NONE;
|
320 |
return IgnoreReason.NONE;
|
297 |
}
|
321 |
}
|
298 |
|
322 |
|
- |
|
323 |
final IgnoreReason addEcheance(final SQLRowValues prlvt) {
|
- |
|
324 |
Date date = prlvt.getDate("DATE").getTime();
|
- |
|
325 |
|
- |
|
326 |
// don't ask direct debit too far in advance
|
- |
|
327 |
if (date.after(this.upperBound)) {
|
- |
|
328 |
return IgnoreReason.TOO_FAR_IN_FUTURE;
|
- |
|
329 |
} else if (date.before(this.lowerBound)) {
|
- |
|
330 |
date = this.lowerBound;
|
- |
|
331 |
}
|
- |
|
332 |
|
- |
|
333 |
final Element elem;
|
- |
|
334 |
try {
|
- |
|
335 |
elem = createDDTx(this.elemCreator, prlvt);
|
- |
|
336 |
} catch (MissingInfoException e) {
|
- |
|
337 |
return IgnoreReason.MISSING_INFO;
|
- |
|
338 |
}
|
- |
|
339 |
|
- |
|
340 |
// needed so that EndToEndId is unique
|
- |
|
341 |
if (!this.invoiceNumbers.add(prlvt.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM")))
|
- |
|
342 |
throw new IllegalStateException("Duplicate invoice number : " + prlvt);
|
- |
|
343 |
final SQLRowAccessor mandate = prlvt.getForeign("ID_SEPA_MANDATE");
|
- |
|
344 |
if (!mandate.getBoolean("ACTIVE"))
|
- |
|
345 |
throw new IllegalStateException("Inactive mandate for " + prlvt);
|
- |
|
346 |
// needed otherwise would have to update seqType while generating
|
- |
|
347 |
// MAYBE sum all invoices for a single mandate, but which date to choose ?
|
- |
|
348 |
if (!this.invoiceMandates.add(mandate.getString("MandateIdentification")))
|
- |
|
349 |
return IgnoreReason.DUPLICATE_MANDATE;
|
- |
|
350 |
|
- |
|
351 |
this.lockedInvoicesIDs.add(prlvt.getIDNumber());
|
- |
|
352 |
ListMap<String, InvoiceElem> bySeqType = this.map.get(date);
|
- |
|
353 |
if (bySeqType == null) {
|
- |
|
354 |
bySeqType = new ListMap<>();
|
- |
|
355 |
this.map.put(date, bySeqType);
|
- |
|
356 |
}
|
- |
|
357 |
bySeqType.add(mandate.getString("SequenceType"), new InvoiceElem(prlvt, elem));
|
- |
|
358 |
|
- |
|
359 |
this.sum = this.sum.add(BigDecimal.valueOf(prlvt.getLong("MONTANT")).movePointLeft(2));
|
- |
|
360 |
|
- |
|
361 |
return IgnoreReason.NONE;
|
- |
|
362 |
}
|
- |
|
363 |
|
299 |
public final int getTransactionCount() {
|
364 |
public final int getTransactionCount() {
|
300 |
return this.lockedInvoicesIDs.size();
|
365 |
return this.lockedInvoicesIDs.size();
|
301 |
}
|
366 |
}
|
302 |
|
367 |
|
303 |
public final List<PaymentInfo> getPaymentInfos() {
|
368 |
public final List<PaymentInfo> getPaymentInfos() {
|
Line 321... |
Line 386... |
321 |
private final Collection<? extends Number> passedIDs;
|
386 |
private final Collection<? extends Number> passedIDs;
|
322 |
private final List<SQLRowValues> withDDWithoutMessage;
|
387 |
private final List<SQLRowValues> withDDWithoutMessage;
|
323 |
private final ListMapItf<IgnoreReason, SQLRowValues> ignoredInvoices;
|
388 |
private final ListMapItf<IgnoreReason, SQLRowValues> ignoredInvoices;
|
324 |
private final SQLRow insertedMessage;
|
389 |
private final SQLRow insertedMessage;
|
325 |
private final int invoiceCount;
|
390 |
private final int invoiceCount;
|
- |
|
391 |
private final SQLTable table;
|
326 |
|
392 |
|
327 |
protected GenerationResult(Collection<? extends Number> passedIDs, List<SQLRowValues> withDDWithoutMessage, ListMap<IgnoreReason, SQLRowValues> ignoredInvoices, SQLRow insertedMessage) {
|
393 |
protected GenerationResult(SQLTable table, Collection<? extends Number> passedIDs, List<SQLRowValues> withDDWithoutMessage, ListMap<IgnoreReason, SQLRowValues> ignoredInvoices,
|
- |
|
394 |
SQLRow insertedMessage) {
|
328 |
super();
|
395 |
super();
|
- |
|
396 |
this.table = table;
|
329 |
this.passedIDs = passedIDs;
|
397 |
this.passedIDs = passedIDs;
|
330 |
this.withDDWithoutMessage = Collections.unmodifiableList(withDDWithoutMessage);
|
398 |
this.withDDWithoutMessage = Collections.unmodifiableList(withDDWithoutMessage);
|
331 |
assert !ignoredInvoices.containsKey(null) && !ignoredInvoices.containsKey(IgnoreReason.NONE);
|
399 |
assert !ignoredInvoices.containsKey(null) && !ignoredInvoices.containsKey(IgnoreReason.NONE);
|
332 |
this.ignoredInvoices = ListMap.unmodifiableMap(ignoredInvoices);
|
400 |
this.ignoredInvoices = ListMap.unmodifiableMap(ignoredInvoices);
|
333 |
this.insertedMessage = insertedMessage;
|
401 |
this.insertedMessage = insertedMessage;
|
Line 351... |
Line 419... |
351 |
|
419 |
|
352 |
public final int getIncludedInvoicesCount() {
|
420 |
public final int getIncludedInvoicesCount() {
|
353 |
return this.invoiceCount;
|
421 |
return this.invoiceCount;
|
354 |
}
|
422 |
}
|
355 |
|
423 |
|
- |
|
424 |
public SQLTable getTable() {
|
- |
|
425 |
return table;
|
- |
|
426 |
}
|
- |
|
427 |
|
356 |
@Override
|
428 |
@Override
|
357 |
public String toString() {
|
429 |
public String toString() {
|
358 |
return this.getClass().getSimpleName() + ": of the " + this.passedIDs.size() + " passed, " + this.withDDWithoutMessage.size() + " needed a SDD message, of those "
|
430 |
return this.getClass().getSimpleName() + ": of the " + this.passedIDs.size() + " passed, " + this.withDDWithoutMessage.size() + " needed a SDD message, of those "
|
359 |
+ this.ignoredInvoices.allValues().size() + " were ignored (either being too far in the future or duplicate mandates) ; the inserted row was " + this.insertedMessage;
|
431 |
+ this.ignoredInvoices.allValues().size() + " were ignored (either being too far in the future or duplicate mandates) ; the inserted row was " + this.insertedMessage;
|
360 |
}
|
432 |
}
|
361 |
}
|
433 |
}
|
362 |
|
434 |
|
363 |
public GenerationResult generateXML(Collection<? extends Number> invoiceIDs) throws SQLException {
|
435 |
public GenerationResult generateXML(final SQLTable table, Collection<? extends Number> invoiceIDs) throws SQLException {
|
364 |
final Namespace painNS = Namespace.getNamespace("urn:iso:std:iso:20022:tech:xsd:pain.008.001.02");
|
436 |
final Namespace painNS = Namespace.getNamespace("urn:iso:std:iso:20022:tech:xsd:pain.008.001.02");
|
365 |
final Element rootElem = new Element("Document", painNS);
|
437 |
final Element rootElem = new Element("Document", painNS);
|
366 |
final Namespace xsiNS = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
438 |
final Namespace xsiNS = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
367 |
rootElem.setAttribute("schemaLocation", "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02 pain.008.001.02.xsd", xsiNS);
|
439 |
rootElem.setAttribute("schemaLocation", "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02 pain.008.001.02.xsd", xsiNS);
|
368 |
final Document doc = new Document(rootElem);
|
440 |
final Document doc = new Document(rootElem);
|
Line 392... |
Line 464... |
392 |
sel.setLockStrength(LockStrength.SHARE);
|
464 |
sel.setLockStrength(LockStrength.SHARE);
|
393 |
return sel;
|
465 |
return sel;
|
394 |
}
|
466 |
}
|
395 |
});
|
467 |
});
|
396 |
|
468 |
|
397 |
final SQLTable invoiceT = getDirectory().getElement(SaisieVenteFactureSQLElement.class).getTable();
|
- |
|
398 |
final SQLField invoiceSDDMessageF = invoiceT.getField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME);
|
469 |
final SQLField invoiceSDDMessageF = table.getField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME);
|
399 |
return SQLUtils.executeAtomic(getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<GenerationResult, SQLException>() {
|
470 |
return SQLUtils.executeAtomic(getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<GenerationResult, SQLException>() {
|
400 |
@Override
|
471 |
@Override
|
401 |
public GenerationResult handle(SQLDataSource ds) throws SQLException {
|
472 |
public GenerationResult handle(SQLDataSource ds) throws SQLException {
|
402 |
final SQLRowValues lockedSociété = selSociété.fetchOne(SDDMessageSQLElement.this.rowSociété.getIDNumber());
|
473 |
final SQLRowValues lockedSociété = selSociété.fetchOne(SDDMessageSQLElement.this.rowSociété.getIDNumber());
|
403 |
if (lockedSociété == null)
|
474 |
if (lockedSociété == null)
|
404 |
throw new IllegalStateException("Missing société " + SDDMessageSQLElement.this.rowSociété);
|
475 |
throw new IllegalStateException("Missing société " + SDDMessageSQLElement.this.rowSociété);
|
- |
|
476 |
if (lockedSociété.getString("IBAN").trim().length() == 0) {
|
- |
|
477 |
throw new IllegalStateException("Missing société IBAN " + SDDMessageSQLElement.this.rowSociété);
|
- |
|
478 |
}
|
- |
|
479 |
|
- |
|
480 |
if (lockedSociété.getString("BIC").trim().length() == 0) {
|
- |
|
481 |
throw new IllegalStateException("Missing société BIC " + SDDMessageSQLElement.this.rowSociété);
|
- |
|
482 |
}
|
405 |
|
483 |
|
406 |
// find and lock invoices with TYPE_REGLEMENT direct debit and no message
|
484 |
// find and lock invoices with TYPE_REGLEMENT direct debit and no message
|
407 |
final SQLRowValues invoiceVals = new SQLRowValues(invoiceT);
|
485 |
final SQLRowValues invoiceVals = new SQLRowValues(table);
|
- |
|
486 |
|
- |
|
487 |
final boolean fromInvoices = table.getName().equals("SAISIE_VENTE_FACTURE");
|
- |
|
488 |
if (fromInvoices) {
|
408 |
invoiceVals.putRowValues("ID_CLIENT").putNulls("NOM", "BIC", "IBAN");
|
489 |
invoiceVals.putRowValues("ID_CLIENT").putNulls("NOM", "BIC", "IBAN");
|
409 |
invoiceVals.putRowValues("ID_MODE_REGLEMENT").putNulls("AJOURS", "LENJOUR").putRowValues("ID_SEPA_MANDATE").setAllToNull();
|
490 |
invoiceVals.putRowValues("ID_MODE_REGLEMENT").putNulls("AJOURS", "LENJOUR").putRowValues("ID_SEPA_MANDATE").setAllToNull();
|
410 |
invoiceVals.putNulls("NET_A_PAYER", "DATE", "NUMERO", "NOM");
|
491 |
invoiceVals.putNulls("NET_A_PAYER", "DATE", "NUMERO", "NOM");
|
- |
|
492 |
} else {
|
- |
|
493 |
invoiceVals.putRowValues("ID_CLIENT").putNulls("NOM", "BIC", "IBAN");
|
- |
|
494 |
invoiceVals.putRowValues("ID_SEPA_MANDATE").setAllToNull();
|
- |
|
495 |
invoiceVals.putNulls("MONTANT", "DATE");
|
- |
|
496 |
invoiceVals.putRowValues("ID_MOUVEMENT").putRowValues("ID_PIECE").setAllToNull();
|
- |
|
497 |
}
|
- |
|
498 |
|
411 |
final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(invoiceVals);
|
499 |
final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(invoiceVals);
|
412 |
fetcher.setReturnedRowsUnmodifiable(true);
|
500 |
fetcher.setReturnedRowsUnmodifiable(true);
|
413 |
// required for locking rows and to make sure that there's a SEPA Mandate
|
501 |
// required for locking rows and to make sure that there's a SEPA Mandate
|
414 |
fetcher.setFullOnly(true);
|
502 |
fetcher.setFullOnly(true);
|
415 |
fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
503 |
fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
416 |
@Override
|
504 |
@Override
|
417 |
public SQLSelect transformChecked(SQLSelect sel) {
|
505 |
public SQLSelect transformChecked(SQLSelect sel) {
|
418 |
// we will update FACTURE.ID_MESSAGE
|
506 |
// we will update FACTURE.ID_MESSAGE
|
419 |
sel.setLockStrength(LockStrength.UPDATE);
|
507 |
sel.setLockStrength(LockStrength.UPDATE);
|
- |
|
508 |
if (fromInvoices) {
|
420 |
final SQLSelectJoin join = sel.getJoin(invoiceT.getField("ID_MODE_REGLEMENT"));
|
509 |
final SQLSelectJoin join = sel.getJoin(table.getField("ID_MODE_REGLEMENT"));
|
421 |
join.setWhere(new Where(join.getJoinedTable().getField("ID_TYPE_REGLEMENT"), "=", TypeReglementSQLElement.PRELEVEMENT));
|
510 |
join.setWhere(new Where(join.getJoinedTable().getField("ID_TYPE_REGLEMENT"), "=", TypeReglementSQLElement.PRELEVEMENT));
|
- |
|
511 |
}
|
422 |
return sel;
|
512 |
return sel;
|
423 |
}
|
513 |
}
|
424 |
});
|
514 |
});
|
425 |
final List<SQLRowValues> ddInvoices = fetcher
|
515 |
final List<SQLRowValues> ddInvoices = fetcher
|
426 |
.fetch(new Where(invoiceT.getKey(), invoiceIDs).and(new Where(invoiceSDDMessageF, "=", invoiceSDDMessageF.getForeignTable().getUndefinedIDNumber())));
|
516 |
.fetch(new Where(table.getKey(), invoiceIDs).and(new Where(invoiceSDDMessageF, "=", invoiceSDDMessageF.getForeignTable().getUndefinedIDNumber())));
|
427 |
final InvoicesByPaymentInfo map = new InvoicesByPaymentInfo(lowerBound, upperBound, new ElementCreator(painNS, SDDMessageSQLElement.this.fieldTranslator));
|
517 |
final InvoicesByPaymentInfo map = new InvoicesByPaymentInfo(lowerBound, upperBound, new ElementCreator(painNS, SDDMessageSQLElement.this.fieldTranslator));
|
428 |
final ListMap<IgnoreReason, SQLRowValues> ignoredInvoices = new ListMap<>();
|
518 |
final ListMap<IgnoreReason, SQLRowValues> ignoredInvoices = new ListMap<>();
|
429 |
for (final SQLRowValues invoice : ddInvoices) {
|
519 |
for (final SQLRowValues invoice : ddInvoices) {
|
- |
|
520 |
if (fromInvoices) {
|
430 |
final IgnoreReason ignoredReason = map.addInvoice(invoice);
|
521 |
final IgnoreReason ignoredReason = map.addInvoice(invoice);
|
431 |
if (ignoredReason != IgnoreReason.NONE) {
|
522 |
if (ignoredReason != IgnoreReason.NONE) {
|
432 |
ignoredInvoices.add(ignoredReason, invoice);
|
523 |
ignoredInvoices.add(ignoredReason, invoice);
|
433 |
}
|
524 |
}
|
- |
|
525 |
} else {
|
- |
|
526 |
final IgnoreReason ignoredReason = map.addEcheance(invoice);
|
- |
|
527 |
if (ignoredReason != IgnoreReason.NONE) {
|
- |
|
528 |
ignoredInvoices.add(ignoredReason, invoice);
|
- |
|
529 |
}
|
- |
|
530 |
}
|
434 |
}
|
531 |
}
|
435 |
|
532 |
|
436 |
final SQLRow newMsg;
|
533 |
final SQLRow newMsg;
|
437 |
final int txCount = map.getTransactionCount();
|
534 |
final int txCount = map.getTransactionCount();
|
438 |
if (txCount == 0) {
|
535 |
if (txCount == 0) {
|
Line 479... |
Line 576... |
479 |
}
|
576 |
}
|
480 |
// update message serial
|
577 |
// update message serial
|
481 |
getTable().getDBRoot().setMetadata(SERIAL_MD, msgSerial);
|
578 |
getTable().getDBRoot().setMetadata(SERIAL_MD, msgSerial);
|
482 |
}
|
579 |
}
|
483 |
|
580 |
|
484 |
return new GenerationResult(invoiceIDs, ddInvoices, ignoredInvoices, newMsg);
|
581 |
return new GenerationResult(table, invoiceIDs, ddInvoices, ignoredInvoices, newMsg);
|
485 |
}
|
582 |
}
|
486 |
});
|
583 |
});
|
487 |
}
|
584 |
}
|
488 |
|
585 |
|
489 |
static private Element createGroupHeader(final Namespace painNS, final SQLRowValues lockedSociété, final Calendar now, final String msgSerial, final int txCount, final BigDecimal total) {
|
586 |
static private Element createGroupHeader(final Namespace painNS, final SQLRowValues lockedSociété, final Calendar now, final String msgSerial, final int txCount, final BigDecimal total) {
|
Line 553... |
Line 650... |
553 |
postalAddr.addContent(new Element("AdrLine", painNS).setText(addr.getString("CODE_POSTAL") + " " + addr.getString("VILLE")));
|
650 |
postalAddr.addContent(new Element("AdrLine", painNS).setText(addr.getString("CODE_POSTAL") + " " + addr.getString("VILLE")));
|
554 |
creditor.addContent(postalAddr);
|
651 |
creditor.addContent(postalAddr);
|
555 |
res.addContent(creditor);
|
652 |
res.addContent(creditor);
|
556 |
|
653 |
|
557 |
final Element creditorAccount = new Element("CdtrAcct", painNS);
|
654 |
final Element creditorAccount = new Element("CdtrAcct", painNS);
|
- |
|
655 |
String iban = lockedSociété.getString("IBAN").replaceAll(" ", "");
|
558 |
creditorAccount.addContent(new Element("Id", painNS).addContent(elemCreator.createWithNonEmptyText("IBAN", lockedSociété, "IBAN")));
|
656 |
creditorAccount.addContent(new Element("Id", painNS).addContent(elemCreator.createWithNonEmptyText("IBAN", iban, "IBAN")));
|
559 |
res.addContent(creditorAccount);
|
657 |
res.addContent(creditorAccount);
|
560 |
|
658 |
|
561 |
final Element creditorAgent = new Element("CdtrAgt", painNS);
|
659 |
final Element creditorAgent = new Element("CdtrAgt", painNS);
|
562 |
creditorAgent.addContent(new Element("FinInstnId", painNS).addContent(elemCreator.createWithNonEmptyText("BIC", lockedSociété, "BIC")));
|
660 |
creditorAgent.addContent(new Element("FinInstnId", painNS).addContent(elemCreator.createWithNonEmptyText("BIC", lockedSociété, "BIC")));
|
563 |
res.addContent(creditorAgent);
|
661 |
res.addContent(creditorAgent);
|
Line 590... |
Line 688... |
590 |
paymentId.addContent(elemCreator.createWithNonEmptyText("InstrId", end2endID));
|
688 |
paymentId.addContent(elemCreator.createWithNonEmptyText("InstrId", end2endID));
|
591 |
paymentId.addContent(elemCreator.createWithNonEmptyText("EndToEndId", end2endID));
|
689 |
paymentId.addContent(elemCreator.createWithNonEmptyText("EndToEndId", end2endID));
|
592 |
invoiceElem.get1().addContent(0, paymentId);
|
690 |
invoiceElem.get1().addContent(0, paymentId);
|
593 |
|
691 |
|
594 |
// update mandate fields
|
692 |
// update mandate fields
|
- |
|
693 |
final SQLRowAccessor mandate;
|
- |
|
694 |
if (invoiceElem.get0().contains("ID_SEPA_MANDATE")) {
|
- |
|
695 |
mandate = invoiceElem.get0().getForeign("ID_SEPA_MANDATE");
|
- |
|
696 |
} else {
|
595 |
final SQLRowAccessor mandate = invoiceElem.get0().getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
|
697 |
mandate = invoiceElem.get0().getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
|
- |
|
698 |
}
|
- |
|
699 |
|
596 |
final String seqType = mandate.getString("SequenceType");
|
700 |
final String seqType = mandate.getString("SequenceType");
|
597 |
if (seqType.equals(SEPAMandateSQLElement.SEQ_FIRST)) {
|
701 |
if (seqType.equals(SEPAMandateSQLElement.SEQ_FIRST)) {
|
598 |
mandate.createEmptyUpdateRow().put("SequenceType", SEPAMandateSQLElement.SEQ_RECURRENT).update();
|
702 |
mandate.createEmptyUpdateRow().put("SequenceType", SEPAMandateSQLElement.SEQ_RECURRENT).update();
|
599 |
} else if (seqType.equals(SEPAMandateSQLElement.SEQ_FINAL) || seqType.equals(SEPAMandateSQLElement.SEQ_ONEOFF)) {
|
703 |
} else if (seqType.equals(SEPAMandateSQLElement.SEQ_FINAL) || seqType.equals(SEPAMandateSQLElement.SEQ_ONEOFF)) {
|
600 |
mandate.createEmptyUpdateRow().put("ACTIVE", Boolean.FALSE).update();
|
704 |
mandate.createEmptyUpdateRow().put("ACTIVE", Boolean.FALSE).update();
|
Line 608... |
Line 712... |
608 |
final Element res = new Element("DrctDbtTxInf", painNS);
|
712 |
final Element res = new Element("DrctDbtTxInf", painNS);
|
609 |
|
713 |
|
610 |
res.addContent(new Element("InstdAmt", painNS).setAttribute("Ccy", "EUR").setText(getInvoiceAmount(invoice).toPlainString()));
|
714 |
res.addContent(new Element("InstdAmt", painNS).setAttribute("Ccy", "EUR").setText(getInvoiceAmount(invoice).toPlainString()));
|
611 |
|
715 |
|
612 |
final Element mandateRltdInfo = new Element("MndtRltdInf", painNS);
|
716 |
final Element mandateRltdInfo = new Element("MndtRltdInf", painNS);
|
- |
|
717 |
|
- |
|
718 |
final SQLRowAccessor mandate;
|
- |
|
719 |
final boolean fromInvoice = invoice.getTable().getName().equals("SAISIE_VENTE_FACTURE");
|
- |
|
720 |
if (fromInvoice) {
|
613 |
final SQLRowAccessor mandate = invoice.getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
|
721 |
mandate = invoice.getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
|
- |
|
722 |
} else {
|
- |
|
723 |
mandate = invoice.getForeign("ID_SEPA_MANDATE");
|
- |
|
724 |
}
|
614 |
assert !mandate.isUndefined() : "Undefined mandate returned by fetcher";
|
725 |
assert !mandate.isUndefined() : "Undefined mandate returned by fetcher";
|
615 |
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("MndtId", mandate, "MandateIdentification"));
|
726 |
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("MndtId", mandate, "MandateIdentification"));
|
616 |
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("DtOfSgntr", formatDate(mandate.getObjectAs("DateOfSignature", Date.class))));
|
727 |
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("DtOfSgntr", formatDate(mandate.getObjectAs("DateOfSignature", Date.class))));
|
617 |
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("AmdmntInd", "false"));
|
728 |
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("AmdmntInd", "false"));
|
618 |
res.addContent(new Element("DrctDbtTx", painNS).addContent(mandateRltdInfo));
|
729 |
res.addContent(new Element("DrctDbtTx", painNS).addContent(mandateRltdInfo));
|
Line 622... |
Line 733... |
622 |
res.addContent(new Element("Dbtr", painNS).addContent(elemCreator.createWithNonEmptyText("Nm", clientRow, "NOM")));
|
733 |
res.addContent(new Element("Dbtr", painNS).addContent(elemCreator.createWithNonEmptyText("Nm", clientRow, "NOM")));
|
623 |
res.addContent(new Element("DbtrAcct", painNS).addContent(new Element("Id", painNS).addContent(elemCreator.createWithNonEmptyText("IBAN", clientRow, "IBAN"))));
|
734 |
res.addContent(new Element("DbtrAcct", painNS).addContent(new Element("Id", painNS).addContent(elemCreator.createWithNonEmptyText("IBAN", clientRow, "IBAN"))));
|
624 |
|
735 |
|
625 |
res.addContent(new Element("Purp", painNS).addContent(new Element("Cd", painNS).setText("OTHR")));
|
736 |
res.addContent(new Element("Purp", painNS).addContent(new Element("Cd", painNS).setText("OTHR")));
|
626 |
|
737 |
|
- |
|
738 |
final String info;
|
- |
|
739 |
if (fromInvoice) {
|
627 |
final String info = (invoice.getString("NUMERO") + ' ' + invoice.getString("NOM")).trim();
|
740 |
info = (invoice.getString("NUMERO") + ' ' + invoice.getString("NOM")).trim();
|
- |
|
741 |
} else {
|
- |
|
742 |
info = invoice.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM");
|
- |
|
743 |
}
|
628 |
if (!info.isEmpty())
|
744 |
if (!info.isEmpty())
|
629 |
res.addContent(new Element("RmtInf", painNS).addContent(elemCreator.create("Ustrd").setText(elemCreator.shortenText(info, 140))));
|
745 |
res.addContent(new Element("RmtInf", painNS).addContent(elemCreator.create("Ustrd").setText(elemCreator.shortenText(info, 140))));
|
630 |
|
746 |
|
631 |
return res;
|
747 |
return res;
|
632 |
}
|
748 |
}
|