Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/LettragePanel.java |
---|
18,10 → 18,12 |
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer; |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement; |
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement; |
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement; |
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement; |
import org.openconcerto.erp.core.finance.accounting.model.LettrageModel; |
import org.openconcerto.erp.model.ISQLCompteSelector; |
import org.openconcerto.erp.rights.ComptaUserRight; |
import org.openconcerto.erp.utils.LowerCaseFormatFilter; |
import org.openconcerto.erp.utils.UpperCaseFormatFilter; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLElement; |
28,18 → 30,29 |
import org.openconcerto.sql.element.SQLElementDirectory; |
import org.openconcerto.sql.model.SQLBase; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowListRSH; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLSystem; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.UndefinedRowValuesCache; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.request.ComboSQLRequest; |
import org.openconcerto.sql.users.rights.UserRightsManager; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.EditPanel.EditMode; |
import org.openconcerto.sql.view.EditPanelListener; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.FontUtils; |
import org.openconcerto.ui.JDate; |
import org.openconcerto.ui.TitledSeparator; |
import org.openconcerto.ui.warning.JLabelWarning; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.ListMap; |
import org.openconcerto.utils.text.DocumentFilterList; |
import org.openconcerto.utils.text.DocumentFilterList.FilterType; |
import org.openconcerto.utils.text.SimpleDocumentListener; |
63,7 → 76,10 |
import java.text.ParseException; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import java.util.Map.Entry; |
import javax.swing.AbstractAction; |
import javax.swing.BorderFactory; |
85,7 → 101,7 |
public class LettragePanel extends JPanel { |
private ListPanelEcritures ecriturePanel; |
private JTextField codeLettrage; |
private JTextField codeLettrage, codeLettragePartiel; |
private ISQLCompteSelector selCompte; |
private JCheckBox boxValidEcriture, boxAddSousCompte; |
private JPanel warningPanel, warningSolde; |
101,6 → 117,7 |
private int modeSelect; |
private LettrageModel model; |
private JButton buttonLettrer; |
private final JButton buttonRegler = new JButton("Régler"); |
private JDate dateDeb, dateFin, dateLettrage; |
public LettragePanel() { |
162,6 → 179,20 |
this.add(this.codeLettrage, c); |
this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage()); |
JLabel labelCodepartiel = new JLabel("Code lettrage partiel"); |
labelCodepartiel.setHorizontalAlignment(SwingConstants.RIGHT); |
c.gridx++; |
c.gridwidth = 1; |
c.weightx = 0; |
this.add(labelCodepartiel, c); |
this.codeLettragePartiel = new JTextField(10); |
DocumentFilterList.add((AbstractDocument) this.codeLettragePartiel.getDocument(), new LowerCaseFormatFilter(), FilterType.SIMPLE_FILTER); |
c.gridx++; |
c.weightx = 1; |
this.add(this.codeLettragePartiel, c); |
this.codeLettragePartiel.setText(getNextCodeLettragePartiel()); |
// Warning si aucun code rentré |
createPanelWarning(); |
c.gridwidth = GridBagConstraints.REMAINDER; |
323,6 → 354,7 |
this.add(this.boxValidEcriture, c); |
JPanel panelButton = new JPanel(); |
panelButton.add(this.buttonRegler, c); |
// Boutton lettrer |
355,20 → 387,276 |
this.add(buttonClose, c); |
this.buttonLettrer.addActionListener(new ActionListener() { |
public void actionPerformed(ActionEvent e) { |
try { |
int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows(); |
actionLettrage(rowIndex, false); |
} catch (SQLException e1) { |
ExceptionHandler.handle("Erreur de lettrage", e1); |
} |
// System.err.println("Action lettrage sur " + i); |
actionLettrage(rowIndex); |
} |
}); |
this.buttonRegler.addActionListener(new ActionListener() { |
public void actionPerformed(ActionEvent e) { |
final List<SQLRowValues> res = LettragePanel.this.ecriturePanel.getListe().getSelectedRows(); |
final SQLTable tableKm = LettragePanel.this.ecriturePanel.getListe().getSource().getPrimaryTable().getTable("SAISIE_KM"); |
SQLRowValues rowValsKm = new SQLRowValues(tableKm); |
rowValsKm.put("DATE", new Date()); |
rowValsKm.put("ID_JOURNAL", JournalSQLElement.BANQUES); |
long solde = LettragePanel.this.model.getSoldeSelection(); |
final SQLTable tableKmItem = tableKm.getTable("SAISIE_KM_ELEMENT"); |
List<String> pieces = new ArrayList<>(); |
for (SQLRowValues sqlRowValues : res) { |
SQLRowValues rowValsKmItemTiers = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(tableKmItem)); |
rowValsKmItemTiers.put("NUMERO", sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NUMERO")); |
rowValsKmItemTiers.put("NOM", sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NOM")); |
final String pieceNom; |
if (sqlRowValues.getString("NOM_PIECE").trim().length() > 0) { |
pieceNom = sqlRowValues.getString("NOM_PIECE"); |
} else { |
pieceNom = sqlRowValues.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM"); |
} |
rowValsKmItemTiers.put("NOM_PIECE", pieceNom); |
if (pieceNom != null && pieceNom.trim().length() > 0) { |
pieces.add(pieceNom); |
} |
rowValsKmItemTiers.put("CREDIT", sqlRowValues.getLong("DEBIT")); |
rowValsKmItemTiers.put("DEBIT", sqlRowValues.getLong("CREDIT")); |
if (rowValsKmItemTiers.getTable().contains("MONTANT_ECHEANCE")) { |
rowValsKmItemTiers.put("MONTANT_ECHEANCE", sqlRowValues.getLong("CREDIT")); |
} |
rowValsKmItemTiers.put("ID_SAISIE_KM", rowValsKm); |
} |
SQLRowValues rowValsKmItemBq = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(tableKmItem)); |
boolean achat = solde < 0; |
// Compte bq |
int idPce = tableKm.getTable("TYPE_REGLEMENT").getRow(2).getInt("ID_COMPTE_PCE_" + (achat ? "FOURN" : "CLIENT")); |
if (idPce <= 1) { |
try { |
idPce = ComptePCESQLElement.getIdComptePceDefault("VenteCB"); |
} catch (Exception e1) { |
// TODO Auto-generated catch block |
e1.printStackTrace(); |
} |
} |
final SQLTable tableAccount = tableKmItem.getTable("COMPTE_PCE"); |
SQLRow rowCptBq = tableAccount.getRow(idPce); |
rowValsKmItemBq.put("NUMERO", rowCptBq.getString("NUMERO")); |
rowValsKmItemBq.put("NOM", rowCptBq.getString("NOM")); |
if (!pieces.isEmpty()) { |
StringBuilder build = new StringBuilder(); |
int nbPieces = pieces.size(); |
int i = 0; |
for (String string : pieces) { |
build.append(string); |
i++; |
if (i < nbPieces) { |
build.append(", "); |
} |
} |
rowValsKmItemBq.put("NOM_PIECE", build.toString()); |
} |
if (solde > 0) { |
rowValsKmItemBq.put("CREDIT", solde); |
rowValsKmItemBq.put("DEBIT", 0L); |
} else { |
rowValsKmItemBq.put("DEBIT", -solde); |
rowValsKmItemBq.put("CREDIT", 0L); |
} |
rowValsKmItemBq.put("ID_SAISIE_KM", rowValsKm); |
EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("SAISIE_KM"), EditMode.CREATION); |
frame.getSQLComponent().select(rowValsKm); |
frame.setVisible(true); |
frame.addEditPanelListener(new EditPanelListener() { |
@Override |
public void modified() { |
// TODO Auto-generated method stub |
} |
@Override |
public void inserted(int id) { |
List<SQLRow> rowsInserted = tableKm.getRow(id).getReferentRows(tableKmItem); |
List<String> piece = new ArrayList<>(); |
List<SQLRowAccessor> rowsToLettre = new ArrayList<>(); |
long solde = 0; |
for (SQLRowValues sqlRowValues : res) { |
rowsToLettre.add(sqlRowValues); |
final String nomPiece = sqlRowValues.getString("NOM_PIECE"); |
if (sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NUMERO").startsWith("4") && nomPiece.trim().length() > 0) { |
piece.add(nomPiece); |
} |
solde += sqlRowValues.getLong("DEBIT"); |
solde -= sqlRowValues.getLong("CREDIT"); |
} |
for (SQLRow sqlRow : rowsInserted) { |
SQLRow rowEcr = sqlRow.getForeign("ID_ECRITURE"); |
final String nomPiece = sqlRow.getString("NOM_PIECE"); |
if (rowEcr.getString("COMPTE_NUMERO").startsWith("4")) { |
solde += rowEcr.getLong("DEBIT"); |
solde -= rowEcr.getLong("CREDIT"); |
if (nomPiece.trim().length() > 0) { |
piece.add(nomPiece); |
} |
rowsToLettre.add(rowEcr); |
} |
} |
if (solde == 0) { |
final String codeLettre = codeLettrage.getText().trim(); |
for (SQLRowAccessor row2 : rowsToLettre) { |
SQLRowValues rowVals = new SQLRowValues(row2.getTable()); |
// Lettrage |
// On lettre ou relettre la ligne avec le code saisi |
if (codeLettre.length() > 0) { |
rowVals.put("LETTRAGE_PARTIEL", ""); |
rowVals.put("LETTRAGE", codeLettre); |
rowVals.put("DATE_LETTRAGE", dateLettrage.getDate()); |
try { |
rowVals.update(row2.getID()); |
} catch (SQLException e1) { |
e1.printStackTrace(); |
} |
} |
} |
// Mise à jour du code de lettrage |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO"); |
SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow(); |
rowVals.put("CODE_LETTRAGE", codeLettre); |
try { |
rowVals.update(); |
} catch (SQLException e) { |
e.printStackTrace(); |
} |
codeLettrage.setText(getNextCodeLettrage()); |
model.updateTotauxCompte(); |
} else { |
String codeLettreP = codeLettragePartiel.getText().trim(); |
String codeLettre = codeLettrage.getText().trim(); |
SQLSelect selEcr = new SQLSelect(); |
SQLTable tableEcr = tableKm.getTable("ECRITURE"); |
selEcr.addSelect(tableEcr.getKey()); |
selEcr.addSelect(tableEcr.getField("NOM_PIECE")); |
selEcr.addSelect(tableEcr.getField("DEBIT")); |
selEcr.addSelect(tableEcr.getField("CREDIT")); |
selEcr.addSelect(tableEcr.getField("LETTRAGE")); |
selEcr.addSelect(tableEcr.getField("LETTRAGE_PARTIEL")); |
Where w2 = new Where(tableEcr.getField("NOM_PIECE"), piece); |
w2 = w2.and(new Where(tableEcr.getField("COMPTE_NUMERO"), "LIKE", "40%").or(new Where(tableEcr.getField("COMPTE_NUMERO"), "LIKE", "41%"))); |
w2 = w2.and(new Where(tableEcr.getField("DATE_LETTRAGE"), "=", (Object) null)); |
selEcr.setWhere(w2); |
List<SQLRow> rows = SQLRowListRSH.execute(selEcr); |
ListMap<String, SQLRow> mapPiece = new ListMap<>(); |
Map<String, Long> soldePiece = new HashMap<>(); |
for (SQLRow sqlRow : rows) { |
String pieceName = sqlRow.getString("NOM_PIECE"); |
mapPiece.add(pieceName, sqlRow); |
long soldeRow = sqlRow.getLong("DEBIT") - sqlRow.getLong("CREDIT"); |
if (soldePiece.containsKey(pieceName)) { |
soldePiece.put(pieceName, soldePiece.get(pieceName) + soldeRow); |
} else { |
soldePiece.put(pieceName, soldeRow); |
} |
} |
for (Entry<String, List<SQLRow>> entry : mapPiece.entrySet()) { |
if (soldePiece.get(entry.getKey()) == 0) { |
try { |
for (SQLRow rowEcr : entry.getValue()) { |
SQLRowValues rowVals = rowEcr.createEmptyUpdateRow(); |
// Lettrage |
// On lettre ou relettre la ligne avec le code saisi |
if (codeLettre.length() > 0) { |
rowVals.put("LETTRAGE_PARTIEL", ""); |
rowVals.put("LETTRAGE", codeLettre); |
rowVals.put("DATE_LETTRAGE", dateLettrage.getDate()); |
rowVals.update(); |
} |
} |
// Mise à jour du code de lettrage |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO"); |
SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow(); |
rowVals.put("CODE_LETTRAGE", codeLettre); |
rowVals.update(); |
codeLettre = getNextCodeLettrage(); |
} catch (SQLException e) { |
e.printStackTrace(); |
} |
} else { |
try { |
for (SQLRow rowEcr : entry.getValue()) { |
SQLRowValues rowVals = rowEcr.createEmptyUpdateRow(); |
// Lettrage |
// On lettre ou relettre la ligne avec le code saisi |
if (codeLettreP.length() > 0) { |
rowVals.put("LETTRAGE_PARTIEL", codeLettreP); |
rowVals.update(); |
} |
} |
// Mise à jour du code de lettrage |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO"); |
SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow(); |
rowVals.put("CODE_LETTRAGE_PARTIEL", codeLettreP); |
rowVals.update(); |
codeLettreP = getNextCodeLettragePartiel(); |
} catch (SQLException e) { |
e.printStackTrace(); |
} |
} |
} |
codeLettrage.setText(getNextCodeLettrage()); |
codeLettragePartiel.setText(getNextCodeLettragePartiel()); |
model.updateTotauxCompte(); |
} |
} |
@Override |
public void deleted() { |
// TODO Auto-generated method stub |
} |
@Override |
public void cancelled() { |
// TODO Auto-generated method stub |
} |
}); |
} |
}); |
buttonDelettrer.addActionListener(new ActionListener() { |
public void actionPerformed(ActionEvent e) { |
int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows(); |
actionDelettrage(rowIndex); |
actionDelettrage(rowIndex, false); |
} |
}); |
397,6 → 685,7 |
LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0); |
buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0); |
LettragePanel.this.buttonLettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0); |
LettragePanel.this.buttonRegler.setEnabled(!LettragePanel.this.ecriturePanel.getListe().getSelectedRows().isEmpty()); |
} |
}); |
434,27 → 723,59 |
this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0)); |
} |
private String getNextCodeLettragePartiel() { |
return Configuration.getInstance().getDirectory().getElement(NumerotationAutoSQLElement.class).getNextCodeLettragePartiel(); |
} |
private String getNextCodeLettrage() { |
return Configuration.getInstance().getDirectory().getElement(NumerotationAutoSQLElement.class).getNextCodeLettrage(); |
} |
/* Menu clic Droit */ |
private void addActionMenuDroit() { |
// JPopupMenu menu = new JPopupMenu(); |
this.ecriturePanel.getListe().addRowAction(new AbstractAction("Voir la source") { |
PredicateRowAction action = new PredicateRowAction(new AbstractAction() { |
public void actionPerformed(ActionEvent e) { |
SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow(); |
MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT")); |
} |
}, "financing.accouning.entries.source.show"); |
}, false, "financing.accouning.entries.source.show"); |
action.setPredicate(IListeEvent.getSingleSelectionPredicate()); |
// if (this.codeLettrage.getText().trim().length() != 0) { |
this.ecriturePanel.getListe().addIListeAction(action); |
final AbstractAction abstractAction = new AbstractAction() { |
public void actionPerformed(ActionEvent e) { |
try { |
int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows(); |
actionLettrage(rowIndex); |
actionLettrage(rowIndex, false); |
} catch (SQLException e1) { |
ExceptionHandler.handle("erreur de lettrage", e1); |
} |
} |
}; |
this.ecriturePanel.getListe().addRowAction(abstractAction, "financing.accouning.entries.match"); |
PredicateRowAction actionLettre = new PredicateRowAction(abstractAction, false, "financing.accouning.entries.match"); |
actionLettre.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
this.ecriturePanel.getListe().addIListeAction(actionLettre); |
final AbstractAction abstractActionPartiel = new AbstractAction("Lettrage Partiel") { |
public void actionPerformed(ActionEvent e) { |
try { |
int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows(); |
actionLettrage(rowIndex, true); |
} catch (SQLException e1) { |
ExceptionHandler.handle("erreur de lettrage", e1); |
} |
} |
}; |
PredicateRowAction actionLettreP = new PredicateRowAction(abstractActionPartiel, false, "financing.accouning.entries.match.partial"); |
actionLettreP.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
this.ecriturePanel.getListe().addIListeAction(actionLettreP); |
// } |
this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() { |
@Override |
467,13 → 788,20 |
public void actionPerformed(ActionEvent e) { |
int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows(); |
actionDelettrage(rowIndex); |
actionDelettrage(rowIndex, false); |
} |
}, "financing.accouning.entries.unmatch"); |
// menu.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y); |
this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer partiel") { |
public void actionPerformed(ActionEvent e) { |
int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows(); |
actionDelettrage(rowIndex, true); |
} |
}, "financing.accouning.entries.unmatch.partial"); |
} |
/* Panel Warning no numero releve */ |
private void createPanelWarning() { |
525,9 → 853,17 |
} |
// Lettre la ligne passée en parametre |
private void actionLettrage(int[] rowIndex) { |
String codeLettre = this.codeLettrage.getText().trim(); |
private void actionLettrage(int[] rowIndex, boolean partiel) throws SQLException { |
String codeLettre; |
if (partiel) { |
codeLettre = this.codeLettragePartiel.getText().trim(); |
} else { |
codeLettre = this.codeLettrage.getText().trim(); |
} |
// FIXME : transaction |
List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length); |
long solde = 0; |
540,7 → 876,7 |
solde -= ((Long) row.getObject("CREDIT")).longValue(); |
} |
if (solde == 0) { |
if (partiel || solde == 0) { |
for (SQLRow row2 : rowsSelected) { |
555,8 → 891,12 |
EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT")); |
} |
if (partiel) { |
rowVals.put("LETTRAGE_PARTIEL", codeLettre); |
} else { |
rowVals.put("LETTRAGE", codeLettre); |
rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate()); |
} |
try { |
rowVals.update(row2.getID()); |
} catch (SQLException e1) { |
568,7 → 908,11 |
// Mise à jour du code de lettrage |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO"); |
SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow(); |
if (partiel) { |
rowVals.put("CODE_LETTRAGE_PARTIEL", codeLettre); |
} else { |
rowVals.put("CODE_LETTRAGE", codeLettre); |
} |
try { |
rowVals.update(); |
} catch (SQLException e) { |
576,6 → 920,12 |
} |
this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage()); |
if (partiel) { |
this.codeLettragePartiel.setText(getNextCodeLettragePartiel()); |
} else { |
this.codeLettrage.setText(getNextCodeLettrage()); |
} |
this.model.updateTotauxCompte(); |
} |
} |
592,7 → 942,7 |
} |
// Pointe la ligne passée en parametre |
private void actionDelettrage(int[] rowIndex) { |
private void actionDelettrage(int[] rowIndex, boolean partiel) { |
List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length); |
606,11 → 956,22 |
solde -= ((Long) row.getObject("CREDIT")).longValue(); |
} |
if (solde == 0) { |
if (partiel || solde == 0) { |
for (SQLRow row : rowsSelected) { |
SQLRowValues rowVals = new SQLRowValues(this.tableEcr); |
if (partiel) { |
// Dépointage |
if (row.getString("LETTRAGE_PARTIEL").trim().length() != 0) { |
rowVals.put("LETTRAGE_PARTIEL", ""); |
try { |
rowVals.update(row.getID()); |
} catch (SQLException e1) { |
e1.printStackTrace(); |
} |
} |
} else { |
// Dépointage |
if (row.getString("LETTRAGE").trim().length() != 0) { |
624,6 → 985,7 |
} |
} |
} |
} |
this.model.updateTotauxCompte(); |
} |