OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 174 → Rev 177

/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/element/DepotChequeSQLElement.java
13,6 → 13,7
package org.openconcerto.erp.core.finance.payment.element;
 
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.finance.payment.component.DepotChequeSQLComponent;
import org.openconcerto.erp.generationDoc.gestcomm.DepotChequeXmlSheet;
47,7 → 48,7
final List<String> l = new ArrayList<String>();
l.add("DATE");
l.add("NOM");
l.add("ID_BANQUE");
l.add("ID_" + BanqueSQLElement.TABLENAME);
l.add("MONTANT");
return l;
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/element/SDDMessageSQLElement.java
75,10 → 75,12
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ExecutionException;
import java.util.prefs.Preferences;
 
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.SwingWorker;
 
import org.jdom2.Document;
import org.jdom2.Element;
113,12 → 115,30
@Override
public void actionPerformed(ActionEvent e) {
final IListe l = IListe.get(e);
// XML field values are quite large so only fetch them when needed
final SQLTable t = l.getSource().getPrimaryTable();
final Set<Integer> userSelectedIDs = l.getSelection().getUserSelectedIDs();
new SwingWorker<List<SQLRow>, Void>() {
@Override
protected List<SQLRow> doInBackground() throws Exception {
final SQLSelect sel = new SQLSelect().addSelectStar(t);
sel.setWhere(new Where(t.getKey(), l.getSelection().getUserSelectedIDs()));
exportXML(l, SQLRowListRSH.execute(sel));
// XML field values are quite large so only fetch them when needed
sel.setWhere(new Where(t.getKey(), userSelectedIDs));
return SQLRowListRSH.execute(sel);
}
 
@Override
protected void done() {
List<SQLRow> execute;
try {
execute = get();
exportXML(l, execute);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
 
}
}.execute();
}
}, true, false).setPredicate(IListeEvent.getNonEmptySelectionPredicate()));
this.rowSociété = conf.getRowSociete();
this.dbPrefs = new SQLPreferences(conf.getRootSociete());
196,8 → 216,12
}
 
protected static BigDecimal getInvoiceAmount(final SQLRowValues invoice) {
if (invoice.getTable().getName().equals("SAISIE_VENTE_FACTURE")) {
return BigDecimal.valueOf(invoice.getLong("NET_A_PAYER")).movePointLeft(2);
} else {
return BigDecimal.valueOf(invoice.getLong("MONTANT")).movePointLeft(2);
}
}
 
static private final class InvoiceElem extends Tuple2<SQLRowValues, Element> {
protected InvoiceElem(SQLRowValues a, Element b) {
296,6 → 320,47
return IgnoreReason.NONE;
}
 
final IgnoreReason addEcheance(final SQLRowValues prlvt) {
Date date = prlvt.getDate("DATE").getTime();
 
// don't ask direct debit too far in advance
if (date.after(this.upperBound)) {
return IgnoreReason.TOO_FAR_IN_FUTURE;
} else if (date.before(this.lowerBound)) {
date = this.lowerBound;
}
 
final Element elem;
try {
elem = createDDTx(this.elemCreator, prlvt);
} catch (MissingInfoException e) {
return IgnoreReason.MISSING_INFO;
}
 
// needed so that EndToEndId is unique
if (!this.invoiceNumbers.add(prlvt.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM")))
throw new IllegalStateException("Duplicate invoice number : " + prlvt);
final SQLRowAccessor mandate = prlvt.getForeign("ID_SEPA_MANDATE");
if (!mandate.getBoolean("ACTIVE"))
throw new IllegalStateException("Inactive mandate for " + prlvt);
// needed otherwise would have to update seqType while generating
// MAYBE sum all invoices for a single mandate, but which date to choose ?
if (!this.invoiceMandates.add(mandate.getString("MandateIdentification")))
return IgnoreReason.DUPLICATE_MANDATE;
 
this.lockedInvoicesIDs.add(prlvt.getIDNumber());
ListMap<String, InvoiceElem> bySeqType = this.map.get(date);
if (bySeqType == null) {
bySeqType = new ListMap<>();
this.map.put(date, bySeqType);
}
bySeqType.add(mandate.getString("SequenceType"), new InvoiceElem(prlvt, elem));
 
this.sum = this.sum.add(BigDecimal.valueOf(prlvt.getLong("MONTANT")).movePointLeft(2));
 
return IgnoreReason.NONE;
}
 
public final int getTransactionCount() {
return this.lockedInvoicesIDs.size();
}
323,9 → 388,12
private final ListMapItf<IgnoreReason, SQLRowValues> ignoredInvoices;
private final SQLRow insertedMessage;
private final int invoiceCount;
private final SQLTable table;
 
protected GenerationResult(Collection<? extends Number> passedIDs, List<SQLRowValues> withDDWithoutMessage, ListMap<IgnoreReason, SQLRowValues> ignoredInvoices, SQLRow insertedMessage) {
protected GenerationResult(SQLTable table, Collection<? extends Number> passedIDs, List<SQLRowValues> withDDWithoutMessage, ListMap<IgnoreReason, SQLRowValues> ignoredInvoices,
SQLRow insertedMessage) {
super();
this.table = table;
this.passedIDs = passedIDs;
this.withDDWithoutMessage = Collections.unmodifiableList(withDDWithoutMessage);
assert !ignoredInvoices.containsKey(null) && !ignoredInvoices.containsKey(IgnoreReason.NONE);
353,6 → 421,10
return this.invoiceCount;
}
 
public SQLTable getTable() {
return table;
}
 
@Override
public String toString() {
return this.getClass().getSimpleName() + ": of the " + this.passedIDs.size() + " passed, " + this.withDDWithoutMessage.size() + " needed a SDD message, of those "
360,7 → 432,7
}
}
 
public GenerationResult generateXML(Collection<? extends Number> invoiceIDs) throws SQLException {
public GenerationResult generateXML(final SQLTable table, Collection<? extends Number> invoiceIDs) throws SQLException {
final Namespace painNS = Namespace.getNamespace("urn:iso:std:iso:20022:tech:xsd:pain.008.001.02");
final Element rootElem = new Element("Document", painNS);
final Namespace xsiNS = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
394,8 → 466,7
}
});
 
final SQLTable invoiceT = getDirectory().getElement(SaisieVenteFactureSQLElement.class).getTable();
final SQLField invoiceSDDMessageF = invoiceT.getField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME);
final SQLField invoiceSDDMessageF = table.getField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME);
return SQLUtils.executeAtomic(getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<GenerationResult, SQLException>() {
@Override
public GenerationResult handle(SQLDataSource ds) throws SQLException {
402,12 → 473,29
final SQLRowValues lockedSociété = selSociété.fetchOne(SDDMessageSQLElement.this.rowSociété.getIDNumber());
if (lockedSociété == null)
throw new IllegalStateException("Missing société " + SDDMessageSQLElement.this.rowSociété);
if (lockedSociété.getString("IBAN").trim().length() == 0) {
throw new IllegalStateException("Missing société IBAN " + SDDMessageSQLElement.this.rowSociété);
}
 
if (lockedSociété.getString("BIC").trim().length() == 0) {
throw new IllegalStateException("Missing société BIC " + SDDMessageSQLElement.this.rowSociété);
}
 
// find and lock invoices with TYPE_REGLEMENT direct debit and no message
final SQLRowValues invoiceVals = new SQLRowValues(invoiceT);
final SQLRowValues invoiceVals = new SQLRowValues(table);
 
final boolean fromInvoices = table.getName().equals("SAISIE_VENTE_FACTURE");
if (fromInvoices) {
invoiceVals.putRowValues("ID_CLIENT").putNulls("NOM", "BIC", "IBAN");
invoiceVals.putRowValues("ID_MODE_REGLEMENT").putNulls("AJOURS", "LENJOUR").putRowValues("ID_SEPA_MANDATE").setAllToNull();
invoiceVals.putNulls("NET_A_PAYER", "DATE", "NUMERO", "NOM");
} else {
invoiceVals.putRowValues("ID_CLIENT").putNulls("NOM", "BIC", "IBAN");
invoiceVals.putRowValues("ID_SEPA_MANDATE").setAllToNull();
invoiceVals.putNulls("MONTANT", "DATE");
invoiceVals.putRowValues("ID_MOUVEMENT").putRowValues("ID_PIECE").setAllToNull();
}
 
final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(invoiceVals);
fetcher.setReturnedRowsUnmodifiable(true);
// required for locking rows and to make sure that there's a SEPA Mandate
417,21 → 505,30
public SQLSelect transformChecked(SQLSelect sel) {
// we will update FACTURE.ID_MESSAGE
sel.setLockStrength(LockStrength.UPDATE);
final SQLSelectJoin join = sel.getJoin(invoiceT.getField("ID_MODE_REGLEMENT"));
if (fromInvoices) {
final SQLSelectJoin join = sel.getJoin(table.getField("ID_MODE_REGLEMENT"));
join.setWhere(new Where(join.getJoinedTable().getField("ID_TYPE_REGLEMENT"), "=", TypeReglementSQLElement.PRELEVEMENT));
}
return sel;
}
});
final List<SQLRowValues> ddInvoices = fetcher
.fetch(new Where(invoiceT.getKey(), invoiceIDs).and(new Where(invoiceSDDMessageF, "=", invoiceSDDMessageF.getForeignTable().getUndefinedIDNumber())));
.fetch(new Where(table.getKey(), invoiceIDs).and(new Where(invoiceSDDMessageF, "=", invoiceSDDMessageF.getForeignTable().getUndefinedIDNumber())));
final InvoicesByPaymentInfo map = new InvoicesByPaymentInfo(lowerBound, upperBound, new ElementCreator(painNS, SDDMessageSQLElement.this.fieldTranslator));
final ListMap<IgnoreReason, SQLRowValues> ignoredInvoices = new ListMap<>();
for (final SQLRowValues invoice : ddInvoices) {
if (fromInvoices) {
final IgnoreReason ignoredReason = map.addInvoice(invoice);
if (ignoredReason != IgnoreReason.NONE) {
ignoredInvoices.add(ignoredReason, invoice);
}
} else {
final IgnoreReason ignoredReason = map.addEcheance(invoice);
if (ignoredReason != IgnoreReason.NONE) {
ignoredInvoices.add(ignoredReason, invoice);
}
}
}
 
final SQLRow newMsg;
final int txCount = map.getTransactionCount();
481,7 → 578,7
getTable().getDBRoot().setMetadata(SERIAL_MD, msgSerial);
}
 
return new GenerationResult(invoiceIDs, ddInvoices, ignoredInvoices, newMsg);
return new GenerationResult(table, invoiceIDs, ddInvoices, ignoredInvoices, newMsg);
}
});
}
555,7 → 652,8
res.addContent(creditor);
 
final Element creditorAccount = new Element("CdtrAcct", painNS);
creditorAccount.addContent(new Element("Id", painNS).addContent(elemCreator.createWithNonEmptyText("IBAN", lockedSociété, "IBAN")));
String iban = lockedSociété.getString("IBAN").replaceAll(" ", "");
creditorAccount.addContent(new Element("Id", painNS).addContent(elemCreator.createWithNonEmptyText("IBAN", iban, "IBAN")));
res.addContent(creditorAccount);
 
final Element creditorAgent = new Element("CdtrAgt", painNS);
592,7 → 690,13
invoiceElem.get1().addContent(0, paymentId);
 
// update mandate fields
final SQLRowAccessor mandate = invoiceElem.get0().getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
final SQLRowAccessor mandate;
if (invoiceElem.get0().contains("ID_SEPA_MANDATE")) {
mandate = invoiceElem.get0().getForeign("ID_SEPA_MANDATE");
} else {
mandate = invoiceElem.get0().getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
}
 
final String seqType = mandate.getString("SequenceType");
if (seqType.equals(SEPAMandateSQLElement.SEQ_FIRST)) {
mandate.createEmptyUpdateRow().put("SequenceType", SEPAMandateSQLElement.SEQ_RECURRENT).update();
610,7 → 714,14
res.addContent(new Element("InstdAmt", painNS).setAttribute("Ccy", "EUR").setText(getInvoiceAmount(invoice).toPlainString()));
 
final Element mandateRltdInfo = new Element("MndtRltdInf", painNS);
final SQLRowAccessor mandate = invoice.getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
 
final SQLRowAccessor mandate;
final boolean fromInvoice = invoice.getTable().getName().equals("SAISIE_VENTE_FACTURE");
if (fromInvoice) {
mandate = invoice.getForeign("ID_MODE_REGLEMENT").getForeign("ID_SEPA_MANDATE");
} else {
mandate = invoice.getForeign("ID_SEPA_MANDATE");
}
assert !mandate.isUndefined() : "Undefined mandate returned by fetcher";
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("MndtId", mandate, "MandateIdentification"));
mandateRltdInfo.addContent(elemCreator.createWithNonEmptyText("DtOfSgntr", formatDate(mandate.getObjectAs("DateOfSignature", Date.class))));
624,7 → 735,12
 
res.addContent(new Element("Purp", painNS).addContent(new Element("Cd", painNS).setText("OTHR")));
 
final String info = (invoice.getString("NUMERO") + ' ' + invoice.getString("NOM")).trim();
final String info;
if (fromInvoice) {
info = (invoice.getString("NUMERO") + ' ' + invoice.getString("NOM")).trim();
} else {
info = invoice.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM");
}
if (!info.isEmpty())
res.addContent(new Element("RmtInf", painNS).addContent(elemCreator.create("Ustrd").setText(elemCreator.shortenText(info, 140))));
 
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/element/ReglerMontantSQLElement.java
15,9 → 15,16
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.FieldPath;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.graph.Path;
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
import org.openconcerto.sql.view.list.SQLTableModelSource;
import org.openconcerto.utils.CollectionUtils;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
 
public class ReglerMontantSQLElement extends ComptaSQLConfElement {
 
28,7 → 35,7
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("DATE");
l.add("ID_ECHEANCE_FOURNISSEUR");
l.add("ID_FOURNISSEUR");
l.add("ID_MODE_REGLEMENT");
l.add("MONTANT");
return l;
41,6 → 48,27
return l;
}
 
@Override
protected void _initTableSource(SQLTableModelSource res) {
super._initTableSource(res);
final BaseSQLTableModelColumn racCol = new BaseSQLTableModelColumn("Report échéance", Boolean.class) {
@Override
protected Object show_(SQLRowAccessor r) {
 
return !r.getForeign("ID_MODE_REGLEMENT").getBoolean("COMPTANT");
}
 
@Override
public Set<FieldPath> getPaths() {
Path p = new Path(getTable());
Path p2 = p.add(p.getLast().getField("ID_MODE_REGLEMENT"));
return CollectionUtils.createSet(new FieldPath(p2, "COMPTANT"));
}
};
 
res.getColumns().add(racCol);
}
 
public SQLComponent createComponent() {
return new ReglerMontantSQLComponent(this);
};
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/element/ReglerMontantSQLComponent.java
16,6 → 16,7
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
import org.openconcerto.erp.core.common.ui.DeviseField;
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
import org.openconcerto.erp.core.finance.payment.component.ModeDeReglementSQLComponent;
import org.openconcerto.erp.core.finance.payment.ui.RegleMontantTable;
import org.openconcerto.erp.generationEcritures.GenerationReglementAchat;
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
145,6 → 146,9
this.addView("ID_MODE_REGLEMENT", BaseSQLComponent.REQ + ";" + BaseSQLComponent.DEC + ";" + BaseSQLComponent.SEP);
final ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
this.add(eltModeRegl, c);
ModeDeReglementSQLComponent modeReglComp;
modeReglComp = (ModeDeReglementSQLComponent) eltModeRegl.getSQLChild();
modeReglComp.addDateCompListener(this.date);
 
this.addRequiredSQLObject(this.date, "DATE");
this.addRequiredSQLObject(this.montant, "MONTANT");
187,9 → 191,6
int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
if (idTypeRegl > TypeReglementSQLElement.TRAITE) {
idTypeRegl = TypeReglementSQLElement.CHEQUE;
}
rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
rowVals.put("COMPTANT", Boolean.TRUE);
rowVals.put("AJOURS", 0);
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/ui/EncaisseMontantTable.java
62,15 → 62,18
 
final SQLTableElement tableElement_Mvt = new SQLTableElement(e.getTable().getField("ID_MOUVEMENT_ECHEANCE"), Integer.class, new DefaultCellEditor(new JTextField()));
tableElement_Mvt.setRenderer(new KeyTableCellRenderer(Configuration.getInstance().getDirectory().getElement("MOUVEMENT")));
tableElement_Mvt.setEditable(false);
list.add(tableElement_Mvt);
 
// Date
final SQLTableElement dateElement = new SQLTableElement(e.getTable().getField("DATE"), Timestamp.class, new TimestampTableCellEditor());
dateElement.setEditable(false);
list.add(dateElement);
 
// Total HT
montantARegler = new SQLTableElement(e.getTable().getField("MONTANT_A_REGLER"), Long.class, new DeviseCellEditor());
montantARegler.setRenderer(new DeviseNiceTableCellRenderer());
montantARegler.setEditable(false);
list.add(montantARegler);
 
// Total HT
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/component/ModeDeReglementSQLComponent.java
15,6 → 15,7
 
import org.openconcerto.erp.config.Log;
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
import org.openconcerto.erp.model.BanqueModifiedListener;
import org.openconcerto.sql.element.BaseSQLComponent;
40,6 → 41,7
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
279,6 → 281,39
});
}
 
public void addDateCompListener(JDate dateParent) {
dateParent.addPropertyChangeListener(new PropertyChangeListener() {
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
ModeDeReglementSQLComponent.this.currentDate = dateParent.getValue();
refreshDatePrev();
}
});
dateParent.addValueListener(new PropertyChangeListener() {
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
ModeDeReglementSQLComponent.this.currentDate = dateParent.getValue();
refreshDatePrev();
}
});
}
 
private void refreshDatePrev() {
if (this.currentDate != null) {
int aJ = this.comboA.getValue().trim().length() == 0 ? 0 : Integer.valueOf(this.comboA.getValue());
int nJ = this.comboLe.getValue().trim().length() == 0 ? 0 : Integer.valueOf(this.comboLe.getValue());
Date d = ModeDeReglementSQLElement.calculDate(aJ, nJ, this.currentDate);
this.datePrev.setDate(d);
} else {
this.datePrev.setDate(null);
}
}
 
private JDate datePrev = new JDate();
private Date currentDate = null;
 
private void createPanelEcheance() {
 
final GridBagConstraints c = new DefaultGridBagConstraints();
290,6 → 325,13
this.comboA.setMinimumSize(new Dimension(60, this.comboA.getMinimumSize().height));
this.comboA.setPreferredSize(new Dimension(60, this.comboA.getMinimumSize().height));
this.comboA.setMaximumSize(new Dimension(60, this.comboA.getMinimumSize().height));
this.comboA.addValueListener(new PropertyChangeListener() {
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
refreshDatePrev();
}
});
this.panelEcheance.add(this.comboA, c);
c.gridx += 1;
c.gridwidth = 1;
300,7 → 342,21
c.fill = GridBagConstraints.HORIZONTAL;
this.buttonDateFacture.setOpaque(false);
this.panelEcheance.add(this.buttonDateFacture, c);
 
c.gridy++;
c.gridx = 0;
c.weightx = 1;
c.gridwidth = 1;
// ((BaseSQLComponent)((ElementSQLObject)getSQLParent()).getSQLParent()).getView("DATE");
this.panelEcheance.add(new JLabel("Soit le"), c);
c.gridx++;
c.gridwidth = 1;
this.datePrev.setEnabled(false);
this.panelEcheance.add(this.datePrev, c);
 
// c.gridy++;
c.gridwidth = 2;
c.gridx = 3;
c.weightx = 0;
c.fill = GridBagConstraints.NONE;
this.buttonFinMois.setOpaque(false);
314,6 → 370,13
this.comboLe.setMinimumSize(new Dimension(60, this.comboLe.getMinimumSize().height));
this.comboLe.setPreferredSize(new Dimension(60, this.comboLe.getMinimumSize().height));
this.comboLe.setMaximumSize(new Dimension(60, this.comboLe.getMinimumSize().height));
this.comboLe.addValueListener(new PropertyChangeListener() {
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
refreshDatePrev();
}
});
this.panelEcheance.add(this.comboLe, c);
this.panelActive = this.panelEcheance;
this.m.put(Mode.ECHEANCE, this.panelEcheance);
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/component/EncaisserMontantSQLComponent.java
17,7 → 17,6
import org.openconcerto.erp.core.common.ui.DeviseField;
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement;
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
import org.openconcerto.sql.Configuration;
66,7 → 65,85
private JLabel labelWarning = new JLabelWarning("Le montant est trop élevé!");
 
private JDate date;
private ElementSQLObject eltModeRegl;
 
final TableModelListener tableListener = new TableModelListener() {
 
@Override
public void tableChanged(TableModelEvent e) {
final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
 
final int rowCount = model.getRowCount();
long total = 0;
for (int i = 0; i < rowCount; i++) {
Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
if (nHT != null) {
total += nHT.longValue();
}
}
 
montant.getDocument().removeDocumentListener(listenerMontant);
montant.setText(GestionDevise.currencyToString(total));
montant.getDocument().addDocumentListener(listenerMontant);
// Selection du mode de reglement
if (getMode() == SQLComponent.Mode.INSERTION) {
if (rowCount >= 1) {
 
MouvementSQLElement element = getElement().getDirectory().getElement(MouvementSQLElement.class);
SQLRowValues row1 = model.getRowValuesAt(0);
if (row1.getObject("ID_MOUVEMENT_ECHEANCE") != null && !row1.isForeignEmpty("ID_MOUVEMENT_ECHEANCE")) {
final int idScr = element.getSourceId(row1.getForeignID("ID_MOUVEMENT_ECHEANCE"));
SQLTable tableMvt = element.getTable();
if (idScr > 1) {
SQLRow rowMvt = tableMvt.getRow(idScr);
String source = rowMvt.getString("SOURCE");
int idSource = rowMvt.getInt("IDSOURCE");
SQLElement eltSource = element.getDirectory().getElement(source);
if (eltSource != null) {
SQLRow rowSource = eltSource.getTable().getRow(idSource);
 
if (rowSource != null) {
SQLRow rowModeRegl = rowSource.getForeignRow("ID_MODE_REGLEMENT");
if (rowModeRegl != null) {
System.err.println("Set mode de règlement");
int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
rowVals.put("COMPTANT", Boolean.TRUE);
rowVals.put("AJOURS", 0);
rowVals.put("LENJOUR", 0);
rowVals.put("ID_" + BanqueSQLElement.TABLENAME, rowModeRegl.getInt("ID_" + BanqueSQLElement.TABLENAME));
eltModeRegl.setValue(rowVals);
}
}
}
}
}
}
}
 
}
if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())
|| e.getColumn() == model.getColumnIndexForElement(table.getMontantAReglerElement())) {
updateWarning();
}
}
};
 
final SimpleDocumentListener listenerMontant = new SimpleDocumentListener() {
 
@Override
public void update(DocumentEvent e) {
table.getRowValuesTable().getRowValuesTableModel().removeTableModelListener(tableListener);
updateMontant(montant.getText());
table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
updateWarning();
 
}
};
 
public EncaisserMontantSQLComponent(SQLElement elt) {
super(elt);
}
84,7 → 161,6
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
this.add(this.table, c);
this.table.getRowValuesTable().setEnabled(false);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = 1;
c.gridy++;
144,11 → 220,13
 
c.gridx++;
c.gridwidth = 3;
c.weightx = 1;
c.fill = GridBagConstraints.NONE;
this.add(this.montant, c);
 
// Warning
c.gridx++;
c.weightx = 0;
c.gridwidth = GridBagConstraints.REMAINDER;
this.labelWarning.setHorizontalAlignment(SwingConstants.RIGHT);
this.add(this.labelWarning, c);
170,9 → 248,12
c.gridy++;
c.gridwidth = GridBagConstraints.REMAINDER;
this.addView("ID_MODE_REGLEMENT", BaseSQLComponent.REQ + ";" + BaseSQLComponent.DEC + ";" + BaseSQLComponent.SEP);
final ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
this.add(eltModeRegl, c);
this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
this.add(this.eltModeRegl, c);
ModeDeReglementSQLComponent modeReglComp;
 
modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild();
modeReglComp.addDateCompListener(this.date);
this.addRequiredSQLObject(this.date, "DATE");
this.addRequiredSQLObject(this.montant, "MONTANT");
 
182,78 → 263,7
this.addSQLObject(new JTextField(), "TIERS");
DefaultGridBagConstraints.lockMinimumSize(this.montant);
 
final TableModelListener tableListener = new TableModelListener() {
 
@Override
public void tableChanged(TableModelEvent e) {
final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
 
final int rowCount = model.getRowCount();
long total = 0;
for (int i = 0; i < rowCount; i++) {
Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
if (nHT != null) {
total += nHT.longValue();
}
}
 
montant.setText(GestionDevise.currencyToString(total));
 
// Selection du mode de reglement
if (getMode() == SQLComponent.Mode.INSERTION) {
if (rowCount >= 1 && model.getRowValuesAt(0).getObject("ID_MOUVEMENT_ECHEANCE") != null && !model.getRowValuesAt(0).isForeignEmpty("ID_MOUVEMENT_ECHEANCE")) {
final int idScr = MouvementSQLElement.getSourceId(model.getRowValuesAt(0).getInt("ID_MOUVEMENT_ECHEANCE"));
SQLTable tableMvt = Configuration.getInstance().getDirectory().getElement("MOUVEMENT").getTable();
if (idScr > 1) {
SQLRow rowMvt = tableMvt.getRow(idScr);
String source = rowMvt.getString("SOURCE");
int idSource = rowMvt.getInt("IDSOURCE");
SQLElement eltSource = Configuration.getInstance().getDirectory().getElement(source);
if (eltSource != null) {
SQLRow rowSource = eltSource.getTable().getRow(idSource);
 
if (rowSource != null) {
SQLRow rowModeRegl = rowSource.getForeignRow("ID_MODE_REGLEMENT");
if (rowModeRegl != null) {
System.err.println("Set mode de règlement");
int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
if (idTypeRegl == TypeReglementSQLElement.INDEFINI) {
idTypeRegl = TypeReglementSQLElement.CHEQUE;
}
rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
rowVals.put("COMPTANT", Boolean.TRUE);
rowVals.put("AJOURS", 0);
rowVals.put("LENJOUR", 0);
rowVals.put("ID_" + BanqueSQLElement.TABLENAME, rowModeRegl.getInt("ID_" + BanqueSQLElement.TABLENAME));
eltModeRegl.setValue(rowVals);
}
}
}
}
}
}
 
}
if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantAReglerElement())) {
updateWarning();
}
}
};
 
this.montant.getDocument().addDocumentListener(new SimpleDocumentListener() {
 
@Override
public void update(DocumentEvent e) {
table.getRowValuesTable().getRowValuesTableModel().removeTableModelListener(tableListener);
updateMontant(montant.getText());
table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
updateWarning();
 
}
});
this.montant.getDocument().addDocumentListener(listenerMontant);
this.table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
 
}