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); |