3,10 → 3,17 |
*/ |
package org.openconcerto.modules.project; |
|
import java.awt.Component; |
import java.awt.FileDialog; |
import java.awt.Frame; |
import java.awt.GridBagConstraints; |
import java.awt.event.ActionEvent; |
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowEvent; |
import java.io.File; |
import java.io.FilenameFilter; |
import java.io.IOException; |
import java.sql.SQLException; |
import java.util.Arrays; |
import java.util.HashMap; |
import java.util.LinkedHashMap; |
13,9 → 20,9 |
import java.util.List; |
import java.util.Map; |
|
import javax.swing.AbstractAction; |
import javax.swing.JFrame; |
import javax.swing.event.ListSelectionEvent; |
import javax.swing.event.ListSelectionListener; |
import javax.swing.JOptionPane; |
import javax.swing.event.TableModelEvent; |
import javax.swing.event.TableModelListener; |
|
22,22 → 29,17 |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.config.Gestion; |
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel; |
import org.openconcerto.modules.project.panel.HistoriqueAffaireBilanPanel; |
import org.openconcerto.erp.core.supplychain.order.action.ImportProductsToOrder; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.model.SQLBase; |
import org.openconcerto.sql.model.SQLField; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.SQLTableEvent; |
import org.openconcerto.sql.model.SQLTableModifiedListener; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.request.ComboSQLRequest; |
import org.openconcerto.sql.view.IListPanel; |
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.PanelFrame; |
import org.openconcerto.ui.SwingThreadUtils; |
import org.openconcerto.ui.state.WindowStateManager; |
import org.openconcerto.utils.cc.ITransformer; |
|
public class ProjectHistory { |
private PanelFrame panelFrame; |
61,16 → 63,12 |
final Map<String, List<String>> mapList = new LinkedHashMap<String, List<String>>(); |
mapList.put("Devis", Arrays.asList("DEVIS")); |
mapList.put("Bons de commande", Arrays.asList("COMMANDE_CLIENT")); |
mapList.put("Chiffrage", Arrays.asList("CHIFFRAGE_COMMANDE_CLIENT")); |
mapList.put("Factures", Arrays.asList("SAISIE_VENTE_FACTURE")); |
mapList.put("Avoirs", Arrays.asList("AVOIR_CLIENT")); |
mapList.put("Demandes d'achat", Arrays.asList("DEMANDE_ACHAT_ELEMENT")); |
mapList.put("Demandes de prix", Arrays.asList("DEMANDE_PRIX")); |
mapList.put("Commandes", Arrays.asList("COMMANDE")); |
mapList.put("Bons de réception", Arrays.asList("BON_RECEPTION")); |
mapList.put("Achats", Arrays.asList("SAISIE_ACHAT")); |
// mapList.put("Factures fournisseurs", Arrays.asList("FACTURE_FOURNISSEUR")); |
mapList.put("Avoirs fournisseurs", Arrays.asList("AVOIR_FOURNISSEUR")); |
|
if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) { |
mapList.put("Temps", Arrays.asList("AFFAIRE_TEMPS")); |
78,31 → 76,12 |
|
mapList.putAll(moduleTab); |
|
final HistoriqueAffaireBilanPanel bilanPanel = new HistoriqueAffaireBilanPanel(); |
|
final ComboSQLRequest request = new org.openconcerto.sql.request.ComboSQLRequest(b.getTable("AFFAIRE"), Arrays.asList("NUMERO", "ID_CLIENT")); |
if (b.getTable("AFFAIRE").contains("ID_SOCIETE_COMMON")) { |
|
final int socID = comptaPropsConfiguration.getSocieteID(); |
request.setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() { |
@Override |
public SQLSelect transformChecked(SQLSelect input) { |
Where w = new Where(b.getTable("AFFAIRE").getField("ID_SOCIETE_COMMON"), "=", (Object) null).or(new Where(b.getTable("AFFAIRE").getField("ID_SOCIETE_COMMON"), "=", 1)) |
.or(new Where(b.getTable("AFFAIRE").getField("ID_SOCIETE_COMMON"), "=", socID)); |
|
input.andWhere(w); |
return input; |
} |
}); |
} |
request.setUndefLabel("Toutes les affaires"); |
request.setFieldSeparator(" "); |
Map<String, String> splitter = new HashMap<String, String>(); |
splitter.put("DEMANDE_ACHAT_ELEMENT", "ID_FAMILLE_ARTICLE"); |
Map<SQLTable, SQLField> fieldLink = new HashMap<SQLTable, SQLField>(); |
fieldLink.put(b.getTable("CHIFFRAGE_COMMANDE_CLIENT"), b.getTable("CHIFFRAGE_COMMANDE_CLIENT").getField("ID_COMMANDE_CLIENT")); |
this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, bilanPanel, fieldLink, "Toutes les affaires", true, null, null, splitter); |
|
this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, null, null, "Toutes les affaires", true, null, null); |
|
final IListPanel listeDevis = listPanel.getIListePanelFromTableName("DEVIS"); |
GridBagConstraints c = new DefaultGridBagConstraints(); |
c.gridy = 4; |
118,6 → 97,43 |
} |
}); |
|
final IListPanel listeDmdAchat = listPanel.getIListePanelFromTableName("DEMANDE_ACHAT_ELEMENT"); |
PredicateRowAction actionDrop = new PredicateRowAction(new AbstractAction("Importer depuis Fichier Inventor") { |
|
@Override |
public void actionPerformed(ActionEvent e) { |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource()); |
final FileDialog fd = new FileDialog(frame, "Import fichier inventor", FileDialog.LOAD); |
fd.setFilenameFilter(new FilenameFilter() { |
@Override |
public boolean accept(File dir, String name) { |
return name.endsWith(".xls"); |
} |
}); |
fd.setVisible(true); |
if (fd.getFile() != null) { |
|
ImportProductsToOrder importer = new ImportProductsToOrder(); |
|
int a = JOptionPane.showConfirmDialog(frame, "Etes vous sûr de vouloir importer ces éléments dans l'affaire N°" + listPanel.getSelectedRow().getString("NUMERO") + "?", |
"Import invertor", JOptionPane.YES_NO_OPTION); |
if (a == JOptionPane.YES_OPTION) { |
importer.setRowAffaire(listPanel.getSelectedRow()); |
try { |
importer.importFile(new File(fd.getDirectory(), fd.getFile()), b.getTable("DEMANDE_ACHAT_ELEMENT").getDBRoot()); |
listeDmdAchat.getListe().getModel().updateAll(); |
} catch (IOException e1) { |
org.openconcerto.utils.ExceptionHandler.handle("Erreur lors de l'import du fichier!", e1); |
} catch (SQLException e1) { |
org.openconcerto.utils.ExceptionHandler.handle("Erreur lors de l'import du fichier!", e1); |
} |
} |
} |
} |
}, true); |
actionDrop.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE)); |
listeDmdAchat.getListe().addIListeAction(actionDrop); |
|
final IListPanel listeCmd = listPanel.getIListePanelFromTableName("COMMANDE_CLIENT"); |
final ProjectHistoryCmdBottomPanel cmdPanel = new ProjectHistoryCmdBottomPanel(); |
|
147,97 → 163,15 |
// History |
this.panelFrame = new PanelFrame(this.listPanel, "Historique affaires"); |
this.panelFrame.addWindowListener(new WindowAdapter() { |
|
public void windowClosing(WindowEvent e) { |
listPanel.removeAllTableListener(); |
}; |
|
}); |
|
this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
|
final SQLTableModifiedListener cmdClientListener = new SQLTableModifiedListener() { |
|
@Override |
public void tableModified(SQLTableEvent evt) { |
if (bilanPanel != null) { |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow(); |
if (selectedRow != null) { |
bilanPanel.updateCommandeClient(selectedRow.asRow()); |
} |
} |
} |
}; |
final SQLTableModifiedListener devisListener = new SQLTableModifiedListener() { |
|
@Override |
public void tableModified(SQLTableEvent evt) { |
if (bilanPanel != null) { |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow(); |
if (selectedRow != null) { |
bilanPanel.updateDevis(selectedRow.asRow()); |
} |
} |
} |
}; |
this.panelFrame.addWindowListener(new WindowAdapter() { |
public void windowClosing(WindowEvent e) { |
listPanel.removeAllTableListener(); |
b.getTable("COMMANDE_CLIENT").removeTableModifiedListener(cmdClientListener); |
b.getTable("DEVIS").removeTableModifiedListener(devisListener); |
}; |
}); |
|
b.getTable("COMMANDE_CLIENT").addTableModifiedListener(cmdClientListener); |
b.getTable("DEVIS").addTableModifiedListener(devisListener); |
|
this.listPanel.addListSelectionListener(new ListSelectionListener() { |
|
@Override |
public void valueChanged(ListSelectionEvent arg0) { |
|
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow(); |
if (selectedRow != null) { |
bilanPanel.updateCommandeClient(selectedRow.asRow()); |
bilanPanel.updateDevis(selectedRow.asRow()); |
bilanPanel.updateBilanPreBilan(ProjectHistory.this.listPanel.getIListeFromTableName("COMMANDE")); |
} |
} |
}); |
|
this.listPanel.addListenerTable(new TableModelListener() { |
public void tableChanged(TableModelEvent arg0) { |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow(); |
if (selectedRow != null) { |
bilanPanel.updateBilanPreBilan(ProjectHistory.this.listPanel.getIListeFromTableName("COMMANDE")); |
} |
} |
}, "COMMANDE"); |
|
this.listPanel.addListenerTable(new TableModelListener() { |
public void tableChanged(TableModelEvent arg0) { |
bilanPanel.updateAchat(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_ACHAT"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_FOURNISSEUR")); |
} |
}, "SAISIE_ACHAT"); |
this.listPanel.addListenerTable(new TableModelListener() { |
public void tableChanged(TableModelEvent arg0) { |
bilanPanel.updateAchat(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_ACHAT"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_FOURNISSEUR")); |
} |
}, "AVOIR_FOURNISSEUR"); |
|
this.listPanel.addListenerTable(new TableModelListener() { |
public void tableChanged(TableModelEvent arg0) { |
bilanPanel.updateFacturer(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_VENTE_FACTURE"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_CLIENT")); |
} |
}, "SAISIE_VENTE_FACTURE"); |
|
this.listPanel.addListenerTable(new TableModelListener() { |
public void tableChanged(TableModelEvent arg0) { |
bilanPanel.updateFacturer(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_VENTE_FACTURE"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_CLIENT")); |
} |
}, "AVOIR_CLIENT"); |
} |
|
public PanelFrame getFrame() { |
this.panelFrame.setIconImages(Gestion.getFrameIcon()); |
final WindowStateManager stateManager = new WindowStateManager(this.panelFrame, |