OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Ignore whitespace Rev 145 → Rev 146

/trunk/Modules/Module Project/src/org/openconcerto/modules/project/Module.java
59,6 → 59,7
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.model.graph.Link.Direction;
import org.openconcerto.sql.model.graph.Path;
import org.openconcerto.sql.utils.AlterTable;
import org.openconcerto.sql.utils.SQLCreateTable;
import org.openconcerto.sql.view.EditFrame;
import org.openconcerto.sql.view.IListFrame;
80,7 → 81,8
public final class Module extends AbstractModule {
 
public static final String PROJECT_TABLENAME = "AFFAIRE";
private List<String> listTableAffaire = Arrays.asList("SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "DEVIS", "COMMANDE", "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
private List<String> listTableAffaire = Arrays.asList("DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "DEVIS", "COMMANDE",
"SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
 
public Module(ModuleFactory f) throws IOException {
super(f);
293,6 → 295,10
for (String tableName : this.listTableAffaire) {
if (!tableName.equalsIgnoreCase("DEVIS")) {
final SQLElement elt = dir.getElement(tableName);
if (elt == null) {
JOptionPane.showMessageDialog(null, "Table " + tableName + " manquante");
continue;
}
RowAction action = new RowAction(new AbstractAction("Historique affaire") {
@Override
public void actionPerformed(ActionEvent e) {
423,13 → 429,13
exn.printStackTrace();
}
}
} else {
 
} else if (row.getInt("ID_ETAT_DEVIS") != EtatDevisSQLElement.ACCEPTE) {
SQLRowValues rowVals = rowAffaire.asRowValues();
rowVals.putEmptyLink("ID_DEVIS");
try {
rowVals.update();
} catch (SQLException exn) {
// TODO Bloc catch auto-généré
exn.printStackTrace();
}
}
508,11 → 514,32
 
@Override
protected void setupComponents(final ComponentsContext ctxt) {
 
DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
List<String> table2check = Arrays.asList("DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT");
for (String table : table2check) {
if (root.contains(table)) {
SQLTable tableCR = root.getTable(table);
if (!tableCR.contains("ID_AFFAIRE")) {
try {
AlterTable alt = new AlterTable(tableCR);
alt.addForeignColumn("ID_AFFAIRE", root.getTable("AFFAIRE"));
root.getDBSystemRoot().getDataSource().execute(alt.asString());
String s = "INSERT INTO " + root.getTable("FWK_MODULE_METADATA").getSQLName().quote()
+ "(\"MODULE_NAME\",\"TABLE\",\"FIELD\",\"KEY\",\"MODULE_VERSION\") VALUES('org.openconcerto.modules.project','" + table + "','ID_AFFAIRE',true,10000)";
root.getDBSystemRoot().getDataSource().execute(s);
root.getSchema().updateVersion();
root.refetchTable(tableCR.getName());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
for (String table : this.listTableAffaire) {
if (!table.equalsIgnoreCase("DEVIS"))
ctxt.putAdditionalField(table, "ID_AFFAIRE");
}
 
}
 
@Override
540,10 → 567,164
}
}, MainFrame.CREATE_MENU);
 
// ctxt.addMenuItem(new AbstractAction("Export Affaire") {
// @Override
// public void actionPerformed(ActionEvent e) {
// ProjectImportExport importExport = new
// ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
// importExport.export();
// }
// }, MainFrame.HELP_MENU);
//
// ctxt.addMenuItem(new AbstractAction("Import Affaire") {
// @Override
// public void actionPerformed(ActionEvent e) {
// ProjectImportExport importExport = new
// ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
// importExport.importProjects();
// }
// }, MainFrame.HELP_MENU);
//
// ctxt.addMenuItem(new AbstractAction("Fix ID_AFFAIRE") {
// @Override
// public void actionPerformed(ActionEvent e) {
// {
// SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
// SQLSelect selBadCmd = new SQLSelect();
// selBadCmd.addSelect(tableCmd.getKey());
// selBadCmd.addSelect(tableCmd.getField("ID_AFFAIRE"));
// SQLSelectJoin joinTR = selBadCmd.addBackwardJoin("RIGHT", "tr",
// tableCmd.getTable().getTable("TR_DEVIS").getField("ID_COMMANDE_CLIENT"), null);
// SQLSelectJoin joinDevis = selBadCmd.addJoin("LEFT",
// joinTR.getJoinedTable().getField("ID_DEVIS"));
// SQLSelectJoin joinAff = selBadCmd.addBackwardJoin("LEFT", "aff",
// tableCmd.getTable().getTable("AFFAIRE").getField("ID_DEVIS"), null);
// selBadCmd.addSelect(joinAff.getJoinedTable().getKey());
//
// selBadCmd.setWhere(Where.isNull(tableCmd.getField("ID_AFFAIRE")));
// System.err.println(selBadCmd.asString());
//
// List<Object[]> result = (List<Object[]>)
// tableCmd.getDBSystemRoot().getDataSource().executeA(selBadCmd.asString());
// try {
// for (Object[] objects : result) {
// if (objects[2] != null && objects[2].toString().trim().length() > 0)
// tableCmd.getRow(((Number)
// objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number)
// objects[2]).intValue()).commit();
// }
// } catch (SQLException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
//
// // List<SQLRow> list = SQLRowListRSH.execute(selBadVF);
// }
// {
// SQLTable tableVF = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
// SQLSelect selBadVF = new SQLSelect();
// selBadVF.addSelect(tableVF.getKey());
// selBadVF.addSelect(tableVF.getField("ID_AFFAIRE"));
// SQLSelectJoin joinTR = selBadVF.addBackwardJoin("RIGHT", "tr",
// tableVF.getTable().getTable("TR_COMMANDE_CLIENT").getField("ID_SAISIE_VENTE_FACTURE"),
// null);
// SQLSelectJoin joinCmd = selBadVF.addJoin("LEFT",
// joinTR.getJoinedTable().getField("ID_COMMANDE_CLIENT"));
// selBadVF.addSelect(joinCmd.getJoinedTable().getField("ID_AFFAIRE"));
//
// selBadVF.setWhere(Where.isNull(tableVF.getField("ID_AFFAIRE")));
// System.err.println(selBadVF.asString());
// List<Object[]> result = (List<Object[]>)
// tableVF.getDBSystemRoot().getDataSource().executeA(selBadVF.asString());
// try {
// for (Object[] objects : result) {
// if (objects[2] != null && objects[2].toString().trim().length() > 0)
// tableVF.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE",
// ((Number) objects[2]).intValue()).commit();
// }
// } catch (SQLException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// }
// }
// }, MainFrame.CREATE_MENU);
//
// ctxt.addMenuItem(new AbstractAction("Recalcul Total achat facture prorata") {
// @Override
// public void actionPerformed(ActionEvent e) {
//
// {
// final SQLTable table = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
// SQLRowValues rowValsFact = new SQLRowValues(table);
// rowValsFact.putNulls("SOLDE", "PARTIAL", "T_HA", "T_HT");
//
// final SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
// SQLRowValues rowValsCmd = new SQLRowValues(tableCmd);
// rowValsCmd.putNulls("T_HT");
//
// final SQLTable tableCmdElt = ctxt.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
// SQLRowValues rowValsCmdElt = new SQLRowValues(tableCmdElt);
// rowValsCmdElt.put("ID_COMMANDE_CLIENT", rowValsCmd);
// rowValsCmdElt.putNulls("T_PA_HT", "NIVEAU");
//
// final SQLTable tableTR = table.getTable("TR_COMMANDE_CLIENT");
// SQLRowValues rowValsTR = new SQLRowValues(tableTR);
// rowValsTR.put("ID_SAISIE_VENTE_FACTURE", rowValsFact);
// rowValsTR.put("ID_COMMANDE_CLIENT", rowValsCmd);
//
// SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsFact);
// fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
// @Override
// public SQLSelect transformChecked(SQLSelect input) {
// Where w = new Where(table.getField("SOLDE"), "=", Boolean.TRUE);
// w = w.or(new Where(table.getField("PARTIAL"), "=", Boolean.TRUE));
// input.setWhere(w);
// return input;
// }
// });
//
// List<SQLRowValues> rowVals = fetcher.fetch();
//
// for (SQLRowValues sqlRowValues : rowVals) {
// // Recuperation de la commande
// final Collection<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableTR);
// if (!referentRows.isEmpty()) {
// SQLRowAccessor rowTR = referentRows.iterator().next();
// SQLRowAccessor rowCmd = rowTR.getForeign("ID_COMMANDE_CLIENT");
// final long htCmd = rowCmd.getLong("T_HT");
// if (htCmd != 0) {
//
// BigDecimal totalHA = BigDecimal.ZERO;
// Collection<? extends SQLRowAccessor> elt = rowCmd.getReferentRows(tableCmdElt);
// for (SQLRowAccessor sqlRowAccessor : elt) {
// if (sqlRowAccessor.getInt("NIVEAU") == 1) {
// totalHA = totalHA.add(sqlRowAccessor.getBigDecimal("T_PA_HT"));
// }
// }
// BigDecimal prorata = new BigDecimal((double) sqlRowValues.getLong("T_HT") / (double)
// htCmd);
// try {
// sqlRowValues.createEmptyUpdateRow().put("T_HA",
// totalHA.multiply(prorata).movePointRight(2).setScale(0,
// RoundingMode.HALF_UP).longValue()).update();
// } catch (SQLException e1) {
// e1.printStackTrace();
// }
// }
// }
// }
// }
// }
// }, MainFrame.CREATE_MENU);
 
}
 
@Override
protected void start() {
 
 
 
final JComponent quoteComponent = createQuotePanel();
final JComponent orderComponent = createOrderPanel();
MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
/trunk/Modules/Module Project/src/org/openconcerto/modules/project/ProjectHistory.java
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,7 → 20,9
import java.util.List;
import java.util.Map;
 
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
 
20,12 → 29,16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.config.Gestion;
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel;
import org.openconcerto.erp.core.supplychain.order.action.ImportProductsToOrder;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.model.SQLBase;
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;
 
public class ProjectHistory {
52,6 → 65,9
mapList.put("Bons de commande", Arrays.asList("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("Achats", Arrays.asList("SAISIE_ACHAT"));
 
if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) {
81,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();
 
121,8 → 174,8
 
public PanelFrame getFrame() {
this.panelFrame.setIconImages(Gestion.getFrameIcon());
final WindowStateManager stateManager = new WindowStateManager(this.panelFrame, new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator
+ "HistoAffaires.xml"), true);
final WindowStateManager stateManager = new WindowStateManager(this.panelFrame,
new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + "HistoAffaires.xml"), true);
this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.panelFrame.pack();
this.panelFrame.setLocationRelativeTo(null);