OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 152 | Rev 181 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 152 Rev 170
1
package org.openconcerto.modules.project;
1
package org.openconcerto.modules.project;
2
 
2
 
3
import java.awt.Color;
3
import java.awt.Color;
4
import java.awt.GridBagConstraints;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
5
import java.awt.GridBagLayout;
6
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
7
import java.awt.event.ActionListener;
8
import java.beans.PropertyChangeEvent;
8
import java.beans.PropertyChangeEvent;
9
import java.beans.PropertyChangeListener;
9
import java.beans.PropertyChangeListener;
10
import java.io.IOException;
10
import java.io.IOException;
11
import java.math.BigDecimal;
11
import java.math.BigDecimal;
12
import java.math.RoundingMode;
12
import java.math.RoundingMode;
13
import java.sql.SQLException;
13
import java.sql.SQLException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Arrays;
15
import java.util.Arrays;
16
import java.util.Collection;
16
import java.util.Collection;
17
import java.util.Date;
17
import java.util.Date;
18
import java.util.List;
18
import java.util.List;
19
import java.util.Map;
19
import java.util.Map;
20
import java.util.Set;
20
import java.util.Set;
21
 
21
 
22
import javax.swing.AbstractAction;
22
import javax.swing.AbstractAction;
23
import javax.swing.JButton;
23
import javax.swing.JButton;
24
import javax.swing.JComponent;
24
import javax.swing.JComponent;
25
import javax.swing.JFrame;
25
import javax.swing.JFrame;
26
import javax.swing.JLabel;
26
import javax.swing.JLabel;
27
import javax.swing.JOptionPane;
27
import javax.swing.JOptionPane;
28
import javax.swing.JPanel;
28
import javax.swing.JPanel;
29
import javax.swing.JScrollPane;
29
import javax.swing.JScrollPane;
30
import javax.swing.SwingUtilities;
30
import javax.swing.SwingUtilities;
31
 
31
 
32
import org.openconcerto.erp.action.CreateFrameAbstractAction;
32
import org.openconcerto.erp.action.CreateFrameAbstractAction;
33
import org.openconcerto.erp.config.ComptaPropsConfiguration;
33
import org.openconcerto.erp.config.ComptaPropsConfiguration;
34
import org.openconcerto.erp.config.MainFrame;
34
import org.openconcerto.erp.config.MainFrame;
35
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
35
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
36
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
36
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
37
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
37
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
38
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
38
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
39
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
39
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
40
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
40
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
41
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
41
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
42
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
42
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
43
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
43
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
44
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
44
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
45
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
45
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
46
import org.openconcerto.erp.modules.AbstractModule;
46
import org.openconcerto.erp.modules.AbstractModule;
47
import org.openconcerto.erp.modules.AlterTableRestricted;
47
import org.openconcerto.erp.modules.AlterTableRestricted;
48
import org.openconcerto.erp.modules.ComponentsContext;
48
import org.openconcerto.erp.modules.ComponentsContext;
49
import org.openconcerto.erp.modules.DBContext;
49
import org.openconcerto.erp.modules.DBContext;
50
import org.openconcerto.erp.modules.MenuContext;
50
import org.openconcerto.erp.modules.MenuContext;
51
import org.openconcerto.erp.modules.ModuleFactory;
51
import org.openconcerto.erp.modules.ModuleFactory;
52
import org.openconcerto.modules.project.element.ProjectSQLElement;
52
import org.openconcerto.modules.project.element.ProjectSQLElement;
53
import org.openconcerto.modules.project.element.ProjectStateSQLElement;
53
import org.openconcerto.modules.project.element.ProjectStateSQLElement;
54
import org.openconcerto.modules.project.element.ProjectTypeSQLElement;
54
import org.openconcerto.modules.project.element.ProjectTypeSQLElement;
55
import org.openconcerto.sql.Configuration;
55
import org.openconcerto.sql.Configuration;
56
import org.openconcerto.sql.element.SQLComponent;
56
import org.openconcerto.sql.element.SQLComponent;
57
import org.openconcerto.sql.element.SQLElement;
57
import org.openconcerto.sql.element.SQLElement;
58
import org.openconcerto.sql.element.SQLElementDirectory;
58
import org.openconcerto.sql.element.SQLElementDirectory;
59
import org.openconcerto.sql.model.DBRoot;
59
import org.openconcerto.sql.model.DBRoot;
60
import org.openconcerto.sql.model.FieldPath;
60
import org.openconcerto.sql.model.FieldPath;
61
import org.openconcerto.sql.model.SQLRow;
61
import org.openconcerto.sql.model.SQLRow;
62
import org.openconcerto.sql.model.SQLRowAccessor;
62
import org.openconcerto.sql.model.SQLRowAccessor;
63
import org.openconcerto.sql.model.SQLRowValues;
63
import org.openconcerto.sql.model.SQLRowValues;
64
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
64
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
65
import org.openconcerto.sql.model.SQLSelect;
65
import org.openconcerto.sql.model.SQLSelect;
66
import org.openconcerto.sql.model.SQLSelectJoin;
66
import org.openconcerto.sql.model.SQLSelectJoin;
67
import org.openconcerto.sql.model.SQLTable;
67
import org.openconcerto.sql.model.SQLTable;
68
import org.openconcerto.sql.model.SQLTableEvent;
68
import org.openconcerto.sql.model.SQLTableEvent;
69
import org.openconcerto.sql.model.SQLTableEvent.Mode;
69
import org.openconcerto.sql.model.SQLTableEvent.Mode;
70
import org.openconcerto.sql.model.SQLTableModifiedListener;
70
import org.openconcerto.sql.model.SQLTableModifiedListener;
71
import org.openconcerto.sql.model.Where;
71
import org.openconcerto.sql.model.Where;
72
import org.openconcerto.sql.model.graph.Link.Direction;
72
import org.openconcerto.sql.model.graph.Link.Direction;
73
import org.openconcerto.sql.model.graph.Path;
73
import org.openconcerto.sql.model.graph.Path;
74
import org.openconcerto.sql.request.ComboSQLRequest;
74
import org.openconcerto.sql.request.ComboSQLRequest;
75
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
75
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
76
import org.openconcerto.sql.utils.AlterTable;
76
import org.openconcerto.sql.utils.AlterTable;
77
import org.openconcerto.sql.utils.SQLCreateTable;
77
import org.openconcerto.sql.utils.SQLCreateTable;
78
import org.openconcerto.sql.view.EditFrame;
78
import org.openconcerto.sql.view.EditFrame;
79
import org.openconcerto.sql.view.EditPanel.EditMode;
79
import org.openconcerto.sql.view.EditPanel.EditMode;
80
import org.openconcerto.sql.view.IListFrame;
80
import org.openconcerto.sql.view.IListFrame;
81
import org.openconcerto.sql.view.ListeAddPanel;
81
import org.openconcerto.sql.view.ListeAddPanel;
82
import org.openconcerto.sql.view.column.ColumnFooterRenderer;
82
import org.openconcerto.sql.view.column.ColumnFooterRenderer;
83
import org.openconcerto.sql.view.column.ColumnPanel;
83
import org.openconcerto.sql.view.column.ColumnPanel;
84
import org.openconcerto.sql.view.column.ColumnPanelFetcher;
84
import org.openconcerto.sql.view.column.ColumnPanelFetcher;
85
import org.openconcerto.sql.view.column.ColumnRowRenderer;
85
import org.openconcerto.sql.view.column.ColumnRowRenderer;
86
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
86
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
87
import org.openconcerto.sql.view.list.IListe;
87
import org.openconcerto.sql.view.list.IListe;
88
import org.openconcerto.sql.view.list.RowAction;
88
import org.openconcerto.sql.view.list.RowAction;
89
import org.openconcerto.ui.DefaultGridBagConstraints;
89
import org.openconcerto.ui.DefaultGridBagConstraints;
90
import org.openconcerto.ui.FrameUtil;
90
import org.openconcerto.ui.FrameUtil;
91
import org.openconcerto.ui.PanelFrame;
91
import org.openconcerto.ui.PanelFrame;
92
import org.openconcerto.utils.CollectionUtils;
92
import org.openconcerto.utils.CollectionUtils;
93
import org.openconcerto.utils.ExceptionHandler;
93
import org.openconcerto.utils.ExceptionHandler;
94
import org.openconcerto.utils.Tuple2;
94
import org.openconcerto.utils.Tuple2;
95
import org.openconcerto.utils.cc.IExnClosure;
95
import org.openconcerto.utils.cc.IExnClosure;
96
import org.openconcerto.utils.cc.ITransformer;
96
import org.openconcerto.utils.cc.ITransformer;
97
import org.openconcerto.utils.i18n.TranslationManager;
97
import org.openconcerto.utils.i18n.TranslationManager;
98
 
98
 
99
public final class Module extends AbstractModule {
99
public final class Module extends AbstractModule {
100
 
100
 
101
    public static final String PROJECT_TABLENAME = "AFFAIRE";
101
    public static final String PROJECT_TABLENAME = "AFFAIRE";
102
    private List<String> listTableAffaire = Arrays.asList("DEMANDE_PRIX", "BON_RECEPTION", "DEMANDE_ACHAT_ELEMENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT",
102
    private List<String> listTableAffaire = Arrays.asList("DEMANDE_PRIX", "BON_RECEPTION", "DEMANDE_ACHAT_ELEMENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT",
103
            "DEVIS", "COMMANDE", "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
103
            "DEVIS", "COMMANDE", "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
104
 
104
 
105
    public Module(ModuleFactory f) throws IOException {
105
    public Module(ModuleFactory f) throws IOException {
106
        super(f);
106
        super(f);
107
 
107
 
108
    }
108
    }
109
 
109
 
110
    @Override
110
    @Override
111
    protected void install(DBContext ctxt) throws SQLException, IOException {
111
    protected void install(DBContext ctxt) throws SQLException, IOException {
112
        super.install(ctxt);
112
        super.install(ctxt);
113
 
113
 
114
        if (ctxt.getLastInstalledVersion() == null) {
114
        if (ctxt.getLastInstalledVersion() == null) {
115
 
115
 
116
            if (ctxt.getRoot().getTable(PROJECT_TABLENAME) == null) {
116
            if (ctxt.getRoot().getTable(PROJECT_TABLENAME) == null) {
117
                final SQLCreateTable createTableEtatAff = ctxt.getCreateTable("ETAT_AFFAIRE");
117
                final SQLCreateTable createTableEtatAff = ctxt.getCreateTable("ETAT_AFFAIRE");
118
                createTableEtatAff.addVarCharColumn("NOM", 128);
118
                createTableEtatAff.addVarCharColumn("NOM", 128);
119
 
119
 
120
                final SQLCreateTable createTableType = ctxt.getCreateTable("TYPE_AFFAIRE");
120
                final SQLCreateTable createTableType = ctxt.getCreateTable("TYPE_AFFAIRE");
121
                createTableType.addVarCharColumn("NOM", 256);
121
                createTableType.addVarCharColumn("NOM", 256);
122
 
122
 
123
                // AFFAIRE
123
                // AFFAIRE
124
                final SQLCreateTable createTable = ctxt.getCreateTable(PROJECT_TABLENAME);
124
                final SQLCreateTable createTable = ctxt.getCreateTable(PROJECT_TABLENAME);
125
                createTable.addVarCharColumn("NUMERO", 256);
125
                createTable.addVarCharColumn("NUMERO", 256);
126
                createTable.addVarCharColumn("NOM", 1024);
126
                createTable.addVarCharColumn("NOM", 1024);
127
                createTable.addVarCharColumn("INFOS", 1024);
127
                createTable.addVarCharColumn("INFOS", 1024);
128
                createTable.addForeignColumn("ID_CLIENT", ctxt.getRoot().getTable("CLIENT"));
128
                createTable.addForeignColumn("ID_CLIENT", ctxt.getRoot().getTable("CLIENT"));
129
                createTable.addForeignColumn("ID_DEVIS", ctxt.getRoot().getTable("DEVIS"));
129
                createTable.addForeignColumn("ID_DEVIS", ctxt.getRoot().getTable("DEVIS"));
130
                createTable.addColumn("DATE", "date");
130
                createTable.addColumn("DATE", "date");
131
                createTable.addForeignColumn("ID_COMMERCIAL", ctxt.getRoot().getTable("COMMERCIAL"));
131
                createTable.addForeignColumn("ID_COMMERCIAL", ctxt.getRoot().getTable("COMMERCIAL"));
132
                createTable.addForeignColumn("ID_ETAT_AFFAIRE", createTableEtatAff);
132
                createTable.addForeignColumn("ID_ETAT_AFFAIRE", createTableEtatAff);
133
                createTable.addForeignColumn("ID_TYPE_AFFAIRE", createTableType);
133
                createTable.addForeignColumn("ID_TYPE_AFFAIRE", createTableType);
134
 
134
 
135
                for (String table : this.listTableAffaire) {
135
                for (String table : this.listTableAffaire) {
136
                    SQLTable tableDevis = ctxt.getRoot().getTable(table);
136
                    SQLTable tableDevis = ctxt.getRoot().getTable(table);
137
                    if (!tableDevis.getFieldsName().contains("ID_AFFAIRE")) {
137
                    if (!tableDevis.getFieldsName().contains("ID_AFFAIRE")) {
138
                        AlterTableRestricted alter = ctxt.getAlterTable(table);
138
                        AlterTableRestricted alter = ctxt.getAlterTable(table);
139
                        alter.addForeignColumn("ID_AFFAIRE", createTable);
139
                        alter.addForeignColumn("ID_AFFAIRE", createTable);
140
                    }
140
                    }
141
                }
141
                }
142
 
142
 
143
                ctxt.manipulateData(new IExnClosure<DBRoot, SQLException>() {
143
                ctxt.manipulateData(new IExnClosure<DBRoot, SQLException>() {
144
 
144
 
145
                    @Override
145
                    @Override
146
                    public void executeChecked(DBRoot input) throws SQLException {
146
                    public void executeChecked(DBRoot input) throws SQLException {
147
                        // Undefined Affaire
147
                        // Undefined Affaire
148
                        SQLTable tableAff = input.getTable(PROJECT_TABLENAME);
148
                        SQLTable tableAff = input.getTable(PROJECT_TABLENAME);
149
                        SQLRowValues rowVals = new SQLRowValues(tableAff);
149
                        SQLRowValues rowVals = new SQLRowValues(tableAff);
150
                        rowVals.insert();
150
                        rowVals.insert();
151
 
151
 
152
                        // Etat Affaire
152
                        // Etat Affaire
153
                        SQLTable tableTypeAffaire = input.getTable("TYPE_AFFAIRE");
153
                        SQLTable tableTypeAffaire = input.getTable("TYPE_AFFAIRE");
154
                        rowVals = new SQLRowValues(tableTypeAffaire);
154
                        rowVals = new SQLRowValues(tableTypeAffaire);
155
                        rowVals.put("NOM", "Indéfini");
155
                        rowVals.put("NOM", "Indéfini");
156
                        rowVals.insert();
156
                        rowVals.insert();
157
 
157
 
158
                        // Etat Affaire
158
                        // Etat Affaire
159
                        SQLTable tableEtatAffaire = input.getTable("ETAT_AFFAIRE");
159
                        SQLTable tableEtatAffaire = input.getTable("ETAT_AFFAIRE");
160
                        rowVals = new SQLRowValues(tableEtatAffaire);
160
                        rowVals = new SQLRowValues(tableEtatAffaire);
161
                        rowVals.put("NOM", "Indéfini");
161
                        rowVals.put("NOM", "Indéfini");
162
                        rowVals.insert();
162
                        rowVals.insert();
163
 
163
 
164
                        rowVals.clear();
164
                        rowVals.clear();
165
                        rowVals.put("NOM", "A traiter");
165
                        rowVals.put("NOM", "A traiter");
166
                        rowVals.insert();
166
                        rowVals.insert();
167
 
167
 
168
                        rowVals.clear();
168
                        rowVals.clear();
169
                        rowVals.put("NOM", "En cours");
169
                        rowVals.put("NOM", "En cours");
170
                        rowVals.insert();
170
                        rowVals.insert();
171
 
171
 
172
                        rowVals.clear();
172
                        rowVals.clear();
173
                        rowVals.put("NOM", "Traitement terminé");
173
                        rowVals.put("NOM", "Traitement terminé");
174
                        rowVals.insert();
174
                        rowVals.insert();
175
 
175
 
176
                        rowVals.clear();
176
                        rowVals.clear();
177
                        rowVals.put("NOM", "A facturer");
177
                        rowVals.put("NOM", "A facturer");
178
                        rowVals.insert();
178
                        rowVals.insert();
179
 
179
 
180
                        rowVals.clear();
180
                        rowVals.clear();
181
                        rowVals.put("NOM", "Dossier clos");
181
                        rowVals.put("NOM", "Dossier clos");
182
                        rowVals.insert();
182
                        rowVals.insert();
183
                    }
183
                    }
184
                });
184
                });
185
 
185
 
186
            }
186
            }
187
        }
187
        }
188
 
188
 
189
    }
189
    }
190
 
190
 
191
    @Override
191
    @Override
192
    protected void setupElements(final SQLElementDirectory dir) {
192
    protected void setupElements(final SQLElementDirectory dir) {
193
        super.setupElements(dir);
193
        super.setupElements(dir);
194
        TranslationManager.getInstance().addTranslationStreamFromClass(this.getClass());
194
        TranslationManager.getInstance().addTranslationStreamFromClass(this.getClass());
195
        dir.addSQLElement(ProjectSQLElement.class);
195
        dir.addSQLElement(ProjectSQLElement.class);
196
        dir.addSQLElement(ProjectStateSQLElement.class);
196
        dir.addSQLElement(ProjectStateSQLElement.class);
197
        dir.addSQLElement(ProjectTypeSQLElement.class);
197
        dir.addSQLElement(ProjectTypeSQLElement.class);
198
 
198
 
199
        final SQLElement element = dir.getElement("DEVIS");
199
        final SQLElement element = dir.getElement("DEVIS");
200
        DevisSQLElement eltDevis = dir.getElement(DevisSQLElement.class);
200
        DevisSQLElement eltDevis = dir.getElement(DevisSQLElement.class);
201
        eltDevis.getRowActions().clear();
201
        eltDevis.getRowActions().clear();
202
 
202
 
203
        eltDevis.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
203
        eltDevis.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
204
 
204
 
205
            SQLTable tableDevisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT").getTable();
205
            SQLTable tableDevisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT").getTable();
206
 
206
 
207
            @Override
207
            @Override
208
            protected Object show_(SQLRowAccessor r) {
208
            protected Object show_(SQLRowAccessor r) {
209
 
209
 
210
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableDevisElt);
210
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableDevisElt);
211
                double time = 0;
211
                double time = 0;
212
                for (SQLRowAccessor sqlRowAccessor : rows) {
212
                for (SQLRowAccessor sqlRowAccessor : rows) {
213
                    time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
213
                    time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
214
                }
214
                }
215
                return time;
215
                return time;
216
            }
216
            }
217
 
217
 
218
            @Override
218
            @Override
219
            public Set<FieldPath> getPaths() {
219
            public Set<FieldPath> getPaths() {
220
                SQLTable table = Configuration.getInstance().getDirectory().getElement("DEVIS").getTable();
220
                SQLTable table = Configuration.getInstance().getDirectory().getElement("DEVIS").getTable();
221
                Path p = new Path(table).add(tableDevisElt.getField("ID_DEVIS"));
221
                Path p = new Path(table).add(tableDevisElt.getField("ID_DEVIS"));
222
 
222
 
223
                Path p2 = new Path(table).add(tableDevisElt.getField("ID_DEVIS")).addForeignField("ID_UNITE_VENTE");
223
                Path p2 = new Path(table).add(tableDevisElt.getField("ID_DEVIS")).addForeignField("ID_UNITE_VENTE");
224
                return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
224
                return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
225
            }
225
            }
226
        });
226
        });
227
 
227
 
228
        // Transfert vers facture
228
        // Transfert vers facture
229
        RowAction factureAction = eltDevis.getDevis2FactureAction();
229
        RowAction factureAction = eltDevis.getDevis2FactureAction();
230
        eltDevis.getRowActions().add(factureAction);
230
        eltDevis.getRowActions().add(factureAction);
231
 
231
 
232
        // Transfert vers commande
232
        // Transfert vers commande
233
        RowAction commandeAction = eltDevis.getDevis2CmdCliAction();
233
        RowAction commandeAction = eltDevis.getDevis2CmdCliAction();
234
        eltDevis.getRowActions().add(commandeAction);
234
        eltDevis.getRowActions().add(commandeAction);
235
 
235
 
236
        // Marqué accepté
236
        // Marqué accepté
237
        RowAction accepteAction = getAcceptAction();
237
        RowAction accepteAction = getAcceptAction();
238
        eltDevis.getRowActions().add(accepteAction);
238
        eltDevis.getRowActions().add(accepteAction);
239
 
239
 
240
        // Marqué accepté
240
        // Marqué accepté
241
        RowAction refuseAction = eltDevis.getRefuseAction();
241
        RowAction refuseAction = eltDevis.getRefuseAction();
242
        eltDevis.getRowActions().add(refuseAction);
242
        eltDevis.getRowActions().add(refuseAction);
243
 
243
 
244
        // // Dupliquer
244
        // // Dupliquer
245
        RowAction cloneAction = eltDevis.getCloneAction();
245
        RowAction cloneAction = eltDevis.getCloneAction();
246
        eltDevis.getRowActions().add(cloneAction);
246
        eltDevis.getRowActions().add(cloneAction);
247
 
247
 
248
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(DevisXmlSheet.class);
248
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(DevisXmlSheet.class);
249
        mouseSheetXmlListeListener.setGenerateHeader(true);
249
        mouseSheetXmlListeListener.setGenerateHeader(true);
250
        mouseSheetXmlListeListener.setShowHeader(true);
250
        mouseSheetXmlListeListener.setShowHeader(true);
251
        eltDevis.getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
251
        eltDevis.getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
252
 
252
 
253
        element.addComponentFactory(SQLElement.DEFAULT_COMP_ID, new ITransformer<Tuple2<SQLElement, String>, SQLComponent>() {
253
        element.addComponentFactory(SQLElement.DEFAULT_COMP_ID, new ITransformer<Tuple2<SQLElement, String>, SQLComponent>() {
254
 
254
 
255
            @Override
255
            @Override
256
            public SQLComponent transformChecked(Tuple2<SQLElement, String> input) {
256
            public SQLComponent transformChecked(Tuple2<SQLElement, String> input) {
257
                return new DevisSQLComponent(element) {
257
                return new DevisSQLComponent(element) {
258
 
258
 
259
                    public int insert(SQLRow order) {
259
                    public int insert(SQLRow order) {
260
                        int id = super.insert(order);
260
                        int id = super.insert(order);
261
                        checkAffaire(id);
261
                        checkAffaire(id);
262
                        return id;
262
                        return id;
263
                    }
263
                    }
264
 
264
 
265
                    public void update() {
265
                    public void update() {
266
                        super.update();
266
                        super.update();
267
                        checkAffaire(getSelectedID());
267
                        checkAffaire(getSelectedID());
268
                    }
268
                    }
269
 
269
 
270
                };
270
                };
271
            }
271
            }
272
        });
272
        });
273
 
273
 
274
        final SQLElement elementCmd = dir.getElement("COMMANDE_CLIENT");
274
        final SQLElement elementCmd = dir.getElement("COMMANDE_CLIENT");
275
        elementCmd.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
275
        elementCmd.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
276
 
276
 
277
            SQLTable tableCmdElt = dir.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
277
            SQLTable tableCmdElt = dir.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
278
 
278
 
279
            @Override
279
            @Override
280
            protected Object show_(SQLRowAccessor r) {
280
            protected Object show_(SQLRowAccessor r) {
281
 
281
 
282
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableCmdElt);
282
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableCmdElt);
283
                double time = 0;
283
                double time = 0;
284
                for (SQLRowAccessor sqlRowAccessor : rows) {
284
                for (SQLRowAccessor sqlRowAccessor : rows) {
285
                    time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
285
                    time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
286
                }
286
                }
287
                return time;
287
                return time;
288
            }
288
            }
289
 
289
 
290
            @Override
290
            @Override
291
            public Set<FieldPath> getPaths() {
291
            public Set<FieldPath> getPaths() {
292
                final SQLTable table = elementCmd.getTable();
292
                final SQLTable table = elementCmd.getTable();
293
                final Path p = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT"));
293
                final Path p = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT"));
294
                final Path p2 = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT")).addForeignField("ID_UNITE_VENTE");
294
                final Path p2 = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT")).addForeignField("ID_UNITE_VENTE");
295
                return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
295
                return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
296
            }
296
            }
297
        });
297
        });
298
 
298
 
299
        NumerotationAutoSQLElement.addClass(ProjectSQLElement.class, PROJECT_TABLENAME);
299
        NumerotationAutoSQLElement.addClass(ProjectSQLElement.class, PROJECT_TABLENAME);
300
 
300
 
301
        for (String tableName : this.listTableAffaire) {
301
        for (String tableName : this.listTableAffaire) {
302
            if (!tableName.equalsIgnoreCase("DEVIS")) {
302
            if (!tableName.equalsIgnoreCase("DEVIS")) {
303
                final SQLElement elt = dir.getElement(tableName);
303
                final SQLElement elt = dir.getElement(tableName);
304
                if (elt == null) {
304
                if (elt == null) {
305
                    JOptionPane.showMessageDialog(null, "Table " + tableName + " manquante");
305
                    JOptionPane.showMessageDialog(null, "Table " + tableName + " manquante");
306
                    continue;
306
                    continue;
307
                }
307
                }
308
                RowAction action = new RowAction(new AbstractAction("Historique affaire") {
308
                RowAction action = new RowAction(new AbstractAction("Historique affaire") {
309
                    @Override
309
                    @Override
310
                    public void actionPerformed(ActionEvent e) {
310
                    public void actionPerformed(ActionEvent e) {
311
                        ProjectHistory histo = new ProjectHistory();
311
                        ProjectHistory histo = new ProjectHistory();
312
                        histo.getHistoriquePanel().selectIDinJList(IListe.get(e).getSelectedRow().getForeignID("ID_AFFAIRE"));
312
                        histo.getHistoriquePanel().selectIDinJList(IListe.get(e).getSelectedRow().getForeignID("ID_AFFAIRE"));
313
                        histo.getFrame().setVisible(true);
313
                        histo.getFrame().setVisible(true);
314
                    }
314
                    }
315
                }, false) {
315
                }, false) {
316
 
316
 
317
                    @Override
317
                    @Override
318
                    public boolean enabledFor(IListeEvent evt) {
318
                    public boolean enabledFor(IListeEvent evt) {
319
                        if (evt.getSelectedRows().size() == 1) {
319
                        if (evt.getSelectedRows().size() == 1) {
320
                            SQLRowAccessor r = evt.getSelectedRow();
320
                            SQLRowAccessor r = evt.getSelectedRow();
321
                            return !r.isForeignEmpty("ID_AFFAIRE");
321
                            return !r.isForeignEmpty("ID_AFFAIRE");
322
                        }
322
                        }
323
                        return false;
323
                        return false;
324
                    }
324
                    }
325
                };
325
                };
326
 
326
 
327
                elt.getRowActions().add(action);
327
                elt.getRowActions().add(action);
328
                elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
328
                elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
329
 
329
 
330
                    @Override
330
                    @Override
331
                    protected Object show_(SQLRowAccessor r) {
331
                    protected Object show_(SQLRowAccessor r) {
332
                        if (!r.isForeignEmpty("ID_AFFAIRE") && r.getForeign("ID_AFFAIRE") != null) {
332
                        if (!r.isForeignEmpty("ID_AFFAIRE") && r.getForeign("ID_AFFAIRE") != null) {
333
                            return r.getForeign("ID_AFFAIRE").getString("NUMERO");
333
                            return r.getForeign("ID_AFFAIRE").getString("NUMERO");
334
                        } else {
334
                        } else {
335
                            return "";
335
                            return "";
336
                        }
336
                        }
337
                    }
337
                    }
338
 
338
 
339
                    @Override
339
                    @Override
340
                    public Set<FieldPath> getPaths() {
340
                    public Set<FieldPath> getPaths() {
341
                        SQLTable table = elt.getTable();
341
                        SQLTable table = elt.getTable();
342
                        Path p = new Path(table).add(table.getField("ID_AFFAIRE"));
342
                        Path p = new Path(table).add(table.getField("ID_AFFAIRE"));
343
                        return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
343
                        return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
344
                    }
344
                    }
345
                });
345
                });
346
            }
346
            }
347
        }
347
        }
348
 
348
 
349
        final SQLElement elt = dir.getElement("DEVIS");
349
        final SQLElement elt = dir.getElement("DEVIS");
350
        RowAction action = new RowAction(new AbstractAction("Historique affaire") {
350
        RowAction action = new RowAction(new AbstractAction("Historique affaire") {
351
            @Override
351
            @Override
352
            public void actionPerformed(ActionEvent e) {
352
            public void actionPerformed(ActionEvent e) {
353
                ProjectHistory histo = new ProjectHistory();
353
                ProjectHistory histo = new ProjectHistory();
354
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
354
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
355
                Collection<? extends SQLRowAccessor> l = selectedRow.getReferentRows(selectedRow.getTable().getTable("AFFAIRE"));
355
                Collection<? extends SQLRowAccessor> l = selectedRow.getReferentRows(selectedRow.getTable().getTable("AFFAIRE"));
356
                histo.getHistoriquePanel().selectIDinJList(l.iterator().next().getID());
356
                histo.getHistoriquePanel().selectIDinJList(l.iterator().next().getID());
357
                histo.getFrame().setVisible(true);
357
                histo.getFrame().setVisible(true);
358
            }
358
            }
359
        }, false) {
359
        }, false) {
360
 
360
 
361
            @Override
361
            @Override
362
            public boolean enabledFor(IListeEvent evt) {
362
            public boolean enabledFor(IListeEvent evt) {
363
                if (evt.getSelectedRows().size() == 1) {
363
                if (evt.getSelectedRows().size() == 1) {
364
                    SQLRowAccessor r = evt.getSelectedRow();
364
                    SQLRowAccessor r = evt.getSelectedRow();
365
                    Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("AFFAIRE"));
365
                    Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("AFFAIRE"));
366
                    return l.size() > 0;
366
                    return l.size() > 0;
367
                }
367
                }
368
                return false;
368
                return false;
369
            }
369
            }
370
        };
370
        };
371
 
371
 
372
        elt.getRowActions().add(action);
372
        elt.getRowActions().add(action);
373
 
373
 
374
        elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
374
        elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
375
 
375
 
376
            @Override
376
            @Override
377
            protected Object show_(SQLRowAccessor r) {
377
            protected Object show_(SQLRowAccessor r) {
-
 
378
                final SQLRowAccessor foreignAff = r.getForeign("ID_AFFAIRE");
-
 
379
                if (foreignAff != null && !foreignAff.isUndefined()) {
-
 
380
                    return foreignAff.getString("NUMERO");
-
 
381
                } else {
378
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(elt.getTable().getTable("AFFAIRE"));
382
                    Collection<? extends SQLRowAccessor> rows = r.getReferentRows(elt.getTable().getTable("AFFAIRE"));
379
                if (rows.size() == 1) {
383
                    if (rows.size() == 1) {
380
                    return rows.iterator().next().getString("NUMERO");
384
                        return rows.iterator().next().getString("NUMERO");
381
                } else {
385
                    } else {
382
                    return "";
386
                        return "";
383
                }
387
                    }
384
            }
388
                }
-
 
389
            }
385
 
390
 
386
            @Override
391
            @Override
387
            public Set<FieldPath> getPaths() {
392
            public Set<FieldPath> getPaths() {
388
                SQLTable table = elt.getTable();
393
                SQLTable table = elt.getTable();
-
 
394
                Path pDev = new Path(table).add(table.getField("ID_AFFAIRE"));
389
                Path p = new Path(table).add(table.getTable("AFFAIRE"), Direction.REFERENT);
395
                Path pAff = new Path(table).add(table.getTable("AFFAIRE"), Direction.REFERENT);
390
                return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
396
                return CollectionUtils.createSet(new FieldPath(pDev, "NUMERO"), new FieldPath(pAff, "NUMERO"));
391
            }
397
            }
392
        });
398
        });
393
        new CmdToBrSQLInjector();
399
        new CmdToBrSQLInjector();
394
        new QuoteToOrderSQLInjector();
400
        new QuoteToOrderSQLInjector();
395
        new QuoteToInvoiceSQLInjector();
401
        new QuoteToInvoiceSQLInjector();
396
        new OrderToInvoiceSQLInjector();
402
        new OrderToInvoiceSQLInjector();
397
    }
403
    }
398
 
404
 
399
    public static JFrame checkAffaire(int id) {
405
    public static JFrame checkAffaire(int id) {
400
        return checkAffaire(id, true);
406
        return checkAffaire(id, true);
401
    }
407
    }
402
 
408
 
403
    public static JFrame checkAffaire(int id, final boolean createCommandeClient) {
409
    public static JFrame checkAffaire(int id, final boolean createCommandeClient) {
404
        final SQLTable tableDevis = Configuration.getInstance().getRoot().findTable("DEVIS");
410
        final SQLTable tableDevis = Configuration.getInstance().getRoot().findTable("DEVIS");
405
        final SQLTable tableNum = Configuration.getInstance().getRoot().findTable("NUMEROTATION_AUTO");
411
        final SQLTable tableNum = Configuration.getInstance().getRoot().findTable("NUMEROTATION_AUTO");
406
        final SQLRow row = tableDevis.getRow(id);
412
        final SQLRow row = tableDevis.getRow(id);
407
        final SQLRow rowAffaire = row.getForeign("ID_AFFAIRE");
413
        final SQLRow rowAffaire = row.getForeign("ID_AFFAIRE");
408
        if (rowAffaire == null || rowAffaire.isUndefined()) {
414
        if (rowAffaire == null || rowAffaire.isUndefined()) {
409
            if (row.getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
415
            if (row.getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
410
                // FIXME Vérifier si le devis n'est pas déjà rattaché à une affaire
416
                // FIXME Vérifier si le devis n'est pas déjà rattaché à une affaire
411
 
417
 
412
                JPanel p = new JPanel(new GridBagLayout());
418
                JPanel p = new JPanel(new GridBagLayout());
413
                GridBagConstraints c = new DefaultGridBagConstraints();
419
                GridBagConstraints c = new DefaultGridBagConstraints();
414
                c.gridwidth = GridBagConstraints.REMAINDER;
420
                c.gridwidth = GridBagConstraints.REMAINDER;
415
                p.add(new JLabel("Voulez vous intégrer ce devis sur une affaire existante?"), c);
421
                p.add(new JLabel("Voulez vous intégrer ce devis sur une affaire existante?"), c);
416
                c.gridy++;
422
                c.gridy++;
417
                c.gridwidth = 1;
423
                c.gridwidth = 1;
418
                p.add(new JLabel("Rattacher à l'affaire : "), c);
424
                p.add(new JLabel("Rattacher à l'affaire : "), c);
419
                c.gridx++;
425
                c.gridx++;
420
                final SQLRequestComboBox box = new SQLRequestComboBox();
426
                final SQLRequestComboBox box = new SQLRequestComboBox();
421
                final ComboSQLRequest comboRequest = Configuration.getInstance().getDirectory().getElement("AFFAIRE").getComboRequest(true);
427
                final ComboSQLRequest comboRequest = Configuration.getInstance().getDirectory().getElement("AFFAIRE").getComboRequest(true);
422
                Where w = new Where(comboRequest.getPrimaryTable().getField("ID_CLIENT"), "=", row.getForeignID("ID_CLIENT"));
428
                Where w = new Where(comboRequest.getPrimaryTable().getField("ID_CLIENT"), "=", row.getForeignID("ID_CLIENT"));
423
                comboRequest.setWhere(w);
429
                comboRequest.setWhere(w);
424
                box.uiInit(comboRequest);
430
                box.uiInit(comboRequest);
425
                p.add(box, c);
431
                p.add(box, c);
426
                c.gridy++;
432
                c.gridy++;
427
                c.gridx = 0;
433
                c.gridx = 0;
428
                final JButton buttonApply = new JButton("Appliquer");
434
                final JButton buttonApply = new JButton("Appliquer");
429
                JButton buttonAnnuler = new JButton("Nouvelle affaire");
435
                JButton buttonAnnuler = new JButton("Nouvelle affaire");
430
                p.add(buttonApply, c);
436
                p.add(buttonApply, c);
431
                buttonApply.setEnabled(false);
437
                buttonApply.setEnabled(false);
432
                box.addValueListener(new PropertyChangeListener() {
438
                box.addValueListener(new PropertyChangeListener() {
433
 
439
 
434
                    @Override
440
                    @Override
435
                    public void propertyChange(PropertyChangeEvent evt) {
441
                    public void propertyChange(PropertyChangeEvent evt) {
436
                        buttonApply.setEnabled(box.getSelectedRow() != null);
442
                        buttonApply.setEnabled(box.getSelectedRow() != null);
437
 
443
 
438
                    }
444
                    }
439
                });
445
                });
440
                c.gridx++;
446
                c.gridx++;
441
                p.add(buttonAnnuler, c);
447
                p.add(buttonAnnuler, c);
442
                final PanelFrame f = new PanelFrame(p, "Affection d'un devis à une affaire");
448
                final PanelFrame f = new PanelFrame(p, "Affection d'un devis à une affaire");
443
 
449
 
444
                buttonAnnuler.addActionListener(new ActionListener() {
450
                buttonAnnuler.addActionListener(new ActionListener() {
445
 
451
 
446
                    @Override
452
                    @Override
447
                    public void actionPerformed(ActionEvent ae) {
453
                    public void actionPerformed(ActionEvent ae) {
448
                        f.dispose();
454
                        f.dispose();
449
                        final SQLTable table = tableDevis.getTable(PROJECT_TABLENAME);
455
                        final SQLTable table = tableDevis.getTable(PROJECT_TABLENAME);
450
                        final SQLRowValues rowVals = new SQLRowValues(table);
456
                        final SQLRowValues rowVals = new SQLRowValues(table);
451
 
457
 
452
                        final String nextNumero = NumerotationAutoSQLElement.getNextNumero(ProjectSQLElement.class);
458
                        final String nextNumero = NumerotationAutoSQLElement.getNextNumero(ProjectSQLElement.class);
453
                        rowVals.put("NUMERO", nextNumero);
459
                        rowVals.put("NUMERO", nextNumero);
454
 
460
 
455
                        // incrémentation du numéro auto
461
                        // incrémentation du numéro auto
456
                        final SQLRowValues rowValsNum = new SQLRowValues(tableNum);
462
                        final SQLRowValues rowValsNum = new SQLRowValues(tableNum);
457
                        int val = tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class));
463
                        int val = tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class));
458
                        val++;
464
                        val++;
459
                        rowValsNum.put(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class), new Integer(val));
465
                        rowValsNum.put(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class), new Integer(val));
460
                        try {
466
                        try {
461
                            rowValsNum.update(2);
467
                            rowValsNum.update(2);
462
                        } catch (final SQLException e) {
468
                        } catch (final SQLException e) {
463
                            e.printStackTrace();
469
                            e.printStackTrace();
464
                        }
470
                        }
465
 
471
 
466
                        rowVals.put("ID_DEVIS", row.getID());
472
                        rowVals.put("ID_DEVIS", row.getID());
467
                        rowVals.put("ID_CLIENT", row.getObject("ID_CLIENT"));
473
                        rowVals.put("ID_CLIENT", row.getObject("ID_CLIENT"));
468
                        rowVals.put("ID_COMMERCIAL", row.getObject("ID_COMMERCIAL"));
474
                        rowVals.put("ID_COMMERCIAL", row.getObject("ID_COMMERCIAL"));
469
                        rowVals.put("DATE", new Date());
475
                        rowVals.put("DATE", new Date());
470
                        rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.EN_COURS);
476
                        rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.EN_COURS);
471
 
477
 
472
                        SQLRowValues rowValsDevis = row.asRowValues();
478
                        SQLRowValues rowValsDevis = row.asRowValues();
473
                        rowValsDevis.put("ID_AFFAIRE", rowVals);
479
                        rowValsDevis.put("ID_AFFAIRE", rowVals);
474
 
480
 
475
                        try {
481
                        try {
476
                            int id = rowVals.commit().getID();
482
                            int id = rowVals.commit().getID();
477
                            row.fetchValues();
483
                            row.fetchValues();
478
                            if (createCommandeClient) {
484
                            if (createCommandeClient) {
479
                                Configuration.getInstance().getDirectory().getElement(DevisSQLElement.class).transfertCommandeClient(Arrays.asList(row.asRowValues()));
485
                                Configuration.getInstance().getDirectory().getElement(DevisSQLElement.class).transfertCommandeClient(Arrays.asList(row.asRowValues()));
480
                                EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("AFFAIRE"), EditMode.MODIFICATION);
486
                                EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("AFFAIRE"), EditMode.MODIFICATION);
481
                                frame.selectionId(id);
487
                                frame.selectionId(id);
482
                                FrameUtil.showPacked(frame);
488
                                FrameUtil.showPacked(frame);
483
                            }
489
                            }
484
                        } catch (SQLException exn) {
490
                        } catch (SQLException exn) {
485
                            // TODO Bloc catch auto-généré
491
                            // TODO Bloc catch auto-généré
486
                            exn.printStackTrace();
492
                            exn.printStackTrace();
487
                        }
493
                        }
488
                    }
494
                    }
489
                });
495
                });
490
 
496
 
491
                buttonApply.addActionListener(new ActionListener() {
497
                buttonApply.addActionListener(new ActionListener() {
492
 
498
 
493
                    @Override
499
                    @Override
494
                    public void actionPerformed(ActionEvent e) {
500
                    public void actionPerformed(ActionEvent e) {
495
                        f.dispose();
501
                        f.dispose();
496
 
502
 
497
                        SQLRowValues rowValsDevis = row.asRowValues();
503
                        SQLRowValues rowValsDevis = row.asRowValues();
498
                        rowValsDevis.put("ID_AFFAIRE", box.getSelectedId());
504
                        rowValsDevis.put("ID_AFFAIRE", box.getSelectedId());
499
 
505
 
500
                        try {
506
                        try {
501
                            rowValsDevis.commit();
507
                            rowValsDevis.commit();
-
 
508
                            row.fetchValues();
-
 
509
                            if (createCommandeClient) {
-
 
510
                                Configuration.getInstance().getDirectory().getElement(DevisSQLElement.class).transfertCommandeClient(Arrays.asList(row.asRowValues()));
-
 
511
                            }
502
                        } catch (SQLException exn) {
512
                        } catch (SQLException exn) {
503
                            // TODO Bloc catch auto-généré
513
                            ExceptionHandler.handle("Erreur lors de la création de la commande client!", exn);
504
                            exn.printStackTrace();
-
 
505
                        }
514
                        }
506
                    }
515
                    }
507
                });
516
                });
508
                FrameUtil.show(f);
517
                FrameUtil.show(f);
509
                return f;
518
                return f;
510
            }
519
            }
511
 
520
 
512
        } else if (row.getInt("ID_ETAT_DEVIS") != EtatDevisSQLElement.ACCEPTE) {
521
        } else if (row.getInt("ID_ETAT_DEVIS") != EtatDevisSQLElement.ACCEPTE) {
513
            SQLRowValues rowVals = rowAffaire.asRowValues();
522
            SQLRowValues rowVals = rowAffaire.asRowValues();
514
            rowVals.putEmptyLink("ID_DEVIS");
523
            rowVals.putEmptyLink("ID_DEVIS");
515
            try {
524
            try {
516
                rowVals.update();
525
                rowVals.update();
517
            } catch (SQLException exn) {
526
            } catch (SQLException exn) {
518
                exn.printStackTrace();
527
                exn.printStackTrace();
519
            }
528
            }
520
        }
529
        }
521
        return null;
530
        return null;
522
    }
531
    }
523
 
532
 
524
    List<Integer> idsAsked = new ArrayList<Integer>();
533
    List<Integer> idsAsked = new ArrayList<Integer>();
525
 
534
 
526
    public void checkProjectState(final SQLRowAccessor rowFact) {
535
    public void checkProjectState(final SQLRowAccessor rowFact) {
527
        if (!rowFact.isForeignEmpty("ID_AFFAIRE")) {
536
        if (!rowFact.isForeignEmpty("ID_AFFAIRE")) {
528
            final SQLRowAccessor rowAff = rowFact.getForeign("ID_AFFAIRE");
537
            final SQLRowAccessor rowAff = rowFact.getForeign("ID_AFFAIRE");
529
 
538
 
530
            if (rowAff.getInt("ID_ETAT_AFFAIRE") < ProjectStateSQLElement.DOSSIER_CLOS) {
539
            if (rowAff.getInt("ID_ETAT_AFFAIRE") < ProjectStateSQLElement.DOSSIER_CLOS) {
531
 
540
 
532
                SQLSelect sel = new SQLSelect();
541
                SQLSelect sel = new SQLSelect();
533
                final SQLTable tableVF = rowFact.getTable();
542
                final SQLTable tableVF = rowFact.getTable();
534
                sel.addSelect(tableVF.getField("T_TTC"), "SUM");
543
                sel.addSelect(tableVF.getField("T_TTC"), "SUM");
535
                Where w = new Where(tableVF.getField("ID_AFFAIRE"), "=", rowAff.getID());
544
                Where w = new Where(tableVF.getField("ID_AFFAIRE"), "=", rowAff.getID());
536
                sel.setWhere(w);
545
                sel.setWhere(w);
537
 
546
 
538
                Number total = (Number) tableVF.getDBSystemRoot().getDataSource().executeScalar(sel.asString());
547
                Number total = (Number) tableVF.getDBSystemRoot().getDataSource().executeScalar(sel.asString());
539
 
548
 
540
                long devis = rowAff.getForeign("ID_DEVIS").getLong("T_TTC");
549
                long devis = rowAff.getForeign("ID_DEVIS").getLong("T_TTC");
541
                if (devis == total.longValue()) {
550
                if (devis == total.longValue()) {
542
                    if (!idsAsked.contains(rowFact.getID())) {
551
                    if (!idsAsked.contains(rowFact.getID())) {
543
                        idsAsked.add(rowFact.getID());
552
                        idsAsked.add(rowFact.getID());
544
                        SwingUtilities.invokeLater(new Runnable() {
553
                        SwingUtilities.invokeLater(new Runnable() {
545
 
554
 
546
                            @Override
555
                            @Override
547
                            public void run() {
556
                            public void run() {
548
                                int a = JOptionPane.showConfirmDialog(null, "Voulez vous passer l'affaire " + rowAff.getString("NUMERO") + " dans l'état \"Dossier Clos\"?", "Affaire 100% facturée",
557
                                int a = JOptionPane.showConfirmDialog(null, "Voulez vous passer l'affaire " + rowAff.getString("NUMERO") + " dans l'état \"Dossier Clos\"?", "Affaire 100% facturée",
549
                                        JOptionPane.YES_NO_OPTION);
558
                                        JOptionPane.YES_NO_OPTION);
550
                                if (a == JOptionPane.YES_OPTION) {
559
                                if (a == JOptionPane.YES_OPTION) {
551
                                    SQLRowValues rowVals = rowAff.createEmptyUpdateRow();
560
                                    SQLRowValues rowVals = rowAff.createEmptyUpdateRow();
552
                                    rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.DOSSIER_CLOS);
561
                                    rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.DOSSIER_CLOS);
553
                                    try {
562
                                    try {
554
                                        rowVals.commit();
563
                                        rowVals.commit();
555
                                    } catch (SQLException e) {
564
                                    } catch (SQLException e) {
556
                                        ExceptionHandler.handle("Erreur lors de la mise à jour de l'état de l'affaire", e);
565
                                        ExceptionHandler.handle("Erreur lors de la mise à jour de l'état de l'affaire", e);
557
                                    }
566
                                    }
558
                                }
567
                                }
559
                                idsAsked.remove(Integer.valueOf(rowFact.getID()));
568
                                idsAsked.remove(Integer.valueOf(rowFact.getID()));
560
                            }
569
                            }
561
                        });
570
                        });
562
                    }
571
                    }
563
                }
572
                }
564
 
573
 
565
            }
574
            }
566
        }
575
        }
567
    }
576
    }
568
 
577
 
569
    public RowAction getAcceptAction() {
578
    public RowAction getAcceptAction() {
570
        return new RowAction(new AbstractAction() {
579
        return new RowAction(new AbstractAction() {
571
            public void actionPerformed(ActionEvent e) {
580
            public void actionPerformed(ActionEvent e) {
572
                SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
581
                SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
573
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
582
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
574
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
583
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
575
                try {
584
                try {
576
                    rowVals.update();
585
                    rowVals.update();
577
                } catch (SQLException e1) {
586
                } catch (SQLException e1) {
578
                    e1.printStackTrace();
587
                    e1.printStackTrace();
579
                }
588
                }
580
                selectedRow.getTable().fireTableModified(selectedRow.getID());
589
                selectedRow.getTable().fireTableModified(selectedRow.getID());
581
                checkAffaire(selectedRow.getID());
590
                checkAffaire(selectedRow.getID());
582
            }
591
            }
583
        }, false, "project.accept") {
592
        }, false, "project.accept") {
584
 
593
 
585
            public boolean enabledFor(List<SQLRowValues> selection) {
594
            public boolean enabledFor(List<SQLRowValues> selection) {
586
                if (selection != null && selection.size() == 1) {
595
                if (selection != null && selection.size() == 1) {
587
                    if (selection.get(0).getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
596
                    if (selection.get(0).getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
588
                        return true;
597
                        return true;
589
                    }
598
                    }
590
                }
599
                }
591
                return false;
600
                return false;
592
            };
601
            };
593
 
602
 
594
        };
603
        };
595
    }
604
    }
596
 
605
 
597
    @Override
606
    @Override
598
    protected void setupComponents(final ComponentsContext ctxt) {
607
    protected void setupComponents(final ComponentsContext ctxt) {
599
 
608
 
600
        DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
609
        DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
601
        List<String> table2check = Arrays.asList("BON_RECEPTION", "DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT");
610
        List<String> table2check = Arrays.asList("BON_RECEPTION", "DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT");
602
        for (String table : table2check) {
611
        for (String table : table2check) {
603
            if (root.contains(table)) {
612
            if (root.contains(table)) {
604
                SQLTable tableCR = root.getTable(table);
613
                SQLTable tableCR = root.getTable(table);
605
                if (!tableCR.contains("ID_AFFAIRE")) {
614
                if (!tableCR.contains("ID_AFFAIRE")) {
606
                    try {
615
                    try {
607
                        AlterTable alt = new AlterTable(tableCR);
616
                        AlterTable alt = new AlterTable(tableCR);
608
                        alt.addForeignColumn("ID_AFFAIRE", root.getTable("AFFAIRE"));
617
                        alt.addForeignColumn("ID_AFFAIRE", root.getTable("AFFAIRE"));
609
                        root.getDBSystemRoot().getDataSource().execute(alt.asString());
618
                        root.getDBSystemRoot().getDataSource().execute(alt.asString());
610
                        String s = "INSERT INTO " + root.getTable("FWK_MODULE_METADATA").getSQLName().quote()
619
                        String s = "INSERT INTO " + root.getTable("FWK_MODULE_METADATA").getSQLName().quote()
611
                                + "(\"MODULE_NAME\",\"TABLE\",\"FIELD\",\"KEY\",\"MODULE_VERSION\") VALUES('org.openconcerto.modules.project','" + table + "','ID_AFFAIRE',true,10000)";
620
                                + "(\"MODULE_NAME\",\"TABLE\",\"FIELD\",\"KEY\",\"MODULE_VERSION\") VALUES('org.openconcerto.modules.project','" + table + "','ID_AFFAIRE',true,10000)";
612
                        root.getDBSystemRoot().getDataSource().execute(s);
621
                        root.getDBSystemRoot().getDataSource().execute(s);
613
                        root.getSchema().updateVersion();
622
                        root.getSchema().updateVersion();
614
                        root.refetchTable(tableCR.getName());
623
                        root.refetchTable(tableCR.getName());
615
                    } catch (SQLException e) {
624
                    } catch (SQLException e) {
616
                        e.printStackTrace();
625
                        e.printStackTrace();
617
                    }
626
                    }
618
                }
627
                }
619
            }
628
            }
620
        }
629
        }
621
 
630
 
622
        for (String table : this.listTableAffaire) {
631
        for (String table : this.listTableAffaire) {
623
            if (!table.equalsIgnoreCase("DEVIS"))
632
            if (!table.equalsIgnoreCase("DEVIS"))
624
                ctxt.putAdditionalField(table, "ID_AFFAIRE");
633
                ctxt.putAdditionalField(table, "ID_AFFAIRE");
625
        }
634
        }
626
 
635
 
627
    }
636
    }
628
 
637
 
629
    @Override
638
    @Override
630
    protected void setupMenu(final MenuContext ctxt) {
639
    protected void setupMenu(final MenuContext ctxt) {
631
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des affaires") {
640
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des affaires") {
632
            @Override
641
            @Override
633
            public JFrame createFrame() {
642
            public JFrame createFrame() {
634
                IListFrame frame = new IListFrame(new ListeAddPanel(ctxt.getElement(PROJECT_TABLENAME)));
643
                IListFrame frame = new IListFrame(new ListeAddPanel(ctxt.getElement(PROJECT_TABLENAME)));
635
                return frame;
644
                return frame;
636
            }
645
            }
637
        }, MainFrame.LIST_MENU);
646
        }, MainFrame.LIST_MENU);
638
        ctxt.addMenuItem(new CreateFrameAbstractAction("Historique des affaires") {
647
        ctxt.addMenuItem(new CreateFrameAbstractAction("Historique des affaires") {
639
            @Override
648
            @Override
640
            public JFrame createFrame() {
649
            public JFrame createFrame() {
641
                ProjectHistory histo = new ProjectHistory();
650
                ProjectHistory histo = new ProjectHistory();
642
 
651
 
643
                return histo.getFrame();
652
                return histo.getFrame();
644
            }
653
            }
645
        }, MainFrame.LIST_MENU);
654
        }, MainFrame.LIST_MENU);
646
 
655
 
647
        ctxt.addMenuItem(new CreateFrameAbstractAction("Saisie affaire") {
656
        ctxt.addMenuItem(new CreateFrameAbstractAction("Saisie affaire") {
648
            @Override
657
            @Override
649
            public JFrame createFrame() {
658
            public JFrame createFrame() {
650
                return new EditFrame(ctxt.getElement(PROJECT_TABLENAME));
659
                return new EditFrame(ctxt.getElement(PROJECT_TABLENAME));
651
            }
660
            }
652
        }, MainFrame.CREATE_MENU);
661
        }, MainFrame.CREATE_MENU);
653
 
662
 
654
        addMenuImportExport(ctxt);
663
        addMenuImportExport(ctxt);
655
 
664
 
656
    }
665
    }
657
 
666
 
658
    private void addMenuImportExport(final MenuContext ctxt) {
667
    private void addMenuImportExport(final MenuContext ctxt) {
659
        ////
668
        ////
660
 
669
 
661
        ctxt.addMenuItem(new AbstractAction("Export Affaire") {
670
        ctxt.addMenuItem(new AbstractAction("Export Affaire") {
662
            @Override
671
            @Override
663
            public void actionPerformed(ActionEvent e) {
672
            public void actionPerformed(ActionEvent e) {
664
                ProjectImportExport importExport = new ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
673
                ProjectImportExport importExport = new ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
665
                importExport.export();
674
                importExport.export();
666
            }
675
            }
667
        }, MainFrame.HELP_MENU);
676
        }, MainFrame.HELP_MENU);
668
 
677
 
669
        ctxt.addMenuItem(new AbstractAction("Import Affaire") {
678
        ctxt.addMenuItem(new AbstractAction("Import Affaire") {
670
            @Override
679
            @Override
671
            public void actionPerformed(ActionEvent e) {
680
            public void actionPerformed(ActionEvent e) {
672
                ProjectImportExport importExport = new ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
681
                ProjectImportExport importExport = new ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
673
                importExport.importProjects();
682
                importExport.importProjects();
674
            }
683
            }
675
        }, MainFrame.HELP_MENU);
684
        }, MainFrame.HELP_MENU);
676
 
-
 
-
 
685
        if (false) {
677
        ctxt.addMenuItem(new AbstractAction("Fix ID_AFFAIRE") {
686
            ctxt.addMenuItem(new AbstractAction("Fix ID_AFFAIRE") {
678
            @Override
687
                @Override
679
            public void actionPerformed(ActionEvent e) {
688
                public void actionPerformed(ActionEvent e) {
680
                {
689
                    {
681
                    SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
690
                        SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
682
                    SQLSelect selBadCmd = new SQLSelect();
691
                        SQLSelect selBadCmd = new SQLSelect();
683
                    selBadCmd.addSelect(tableCmd.getKey());
692
                        selBadCmd.addSelect(tableCmd.getKey());
684
                    selBadCmd.addSelect(tableCmd.getField("ID_AFFAIRE"));
693
                        selBadCmd.addSelect(tableCmd.getField("ID_AFFAIRE"));
685
                    SQLSelectJoin joinTR = selBadCmd.addBackwardJoin("RIGHT", "tr", tableCmd.getTable().getTable("TR_DEVIS").getField("ID_COMMANDE_CLIENT"), null);
694
                        SQLSelectJoin joinTR = selBadCmd.addBackwardJoin("RIGHT", "tr", tableCmd.getTable().getTable("TR_DEVIS").getField("ID_COMMANDE_CLIENT"), null);
686
                    SQLSelectJoin joinDevis = selBadCmd.addJoin("LEFT", joinTR.getJoinedTable().getField("ID_DEVIS"));
695
                        SQLSelectJoin joinDevis = selBadCmd.addJoin("LEFT", joinTR.getJoinedTable().getField("ID_DEVIS"));
687
                    SQLSelectJoin joinAff = selBadCmd.addBackwardJoin("LEFT", "aff", tableCmd.getTable().getTable("AFFAIRE").getField("ID_DEVIS"), null);
696
                        SQLSelectJoin joinAff = selBadCmd.addBackwardJoin("LEFT", "aff", tableCmd.getTable().getTable("AFFAIRE").getField("ID_DEVIS"), null);
688
                    selBadCmd.addSelect(joinAff.getJoinedTable().getKey());
697
                        selBadCmd.addSelect(joinAff.getJoinedTable().getKey());
689
 
698
 
690
                    selBadCmd.setWhere(Where.isNull(tableCmd.getField("ID_AFFAIRE")));
699
                        selBadCmd.setWhere(Where.isNull(tableCmd.getField("ID_AFFAIRE")));
691
                    System.err.println(selBadCmd.asString());
700
                        System.err.println(selBadCmd.asString());
692
 
701
 
693
                    List<Object[]> result = (List<Object[]>) tableCmd.getDBSystemRoot().getDataSource().executeA(selBadCmd.asString());
702
                        List<Object[]> result = (List<Object[]>) tableCmd.getDBSystemRoot().getDataSource().executeA(selBadCmd.asString());
694
                    try {
703
                        try {
695
                        for (Object[] objects : result) {
704
                            for (Object[] objects : result) {
696
                            if (objects[2] != null && objects[2].toString().trim().length() > 0)
705
                                if (objects[2] != null && objects[2].toString().trim().length() > 0)
697
                                tableCmd.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number) objects[2]).intValue()).commit();
706
                                    tableCmd.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number) objects[2]).intValue()).commit();
698
                        }
707
                            }
699
                    } catch (SQLException e1) {
708
                        } catch (SQLException e1) {
700
                        // TODO Auto-generated catch block
709
                            // TODO Auto-generated catch block
701
                        e1.printStackTrace();
710
                            e1.printStackTrace();
702
                    }
711
                        }
703
 
712
 
704
                    // List<SQLRow> list = SQLRowListRSH.execute(selBadVF);
713
                        // List<SQLRow> list = SQLRowListRSH.execute(selBadVF);
705
                }
714
                    }
706
                {
715
                    {
707
                    SQLTable tableVF = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
716
                        SQLTable tableVF = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
708
                    SQLSelect selBadVF = new SQLSelect();
717
                        SQLSelect selBadVF = new SQLSelect();
709
                    selBadVF.addSelect(tableVF.getKey());
718
                        selBadVF.addSelect(tableVF.getKey());
710
                    selBadVF.addSelect(tableVF.getField("ID_AFFAIRE"));
719
                        selBadVF.addSelect(tableVF.getField("ID_AFFAIRE"));
711
                    SQLSelectJoin joinTR = selBadVF.addBackwardJoin("RIGHT", "tr", tableVF.getTable().getTable("TR_COMMANDE_CLIENT").getField("ID_SAISIE_VENTE_FACTURE"), null);
720
                        SQLSelectJoin joinTR = selBadVF.addBackwardJoin("RIGHT", "tr", tableVF.getTable().getTable("TR_COMMANDE_CLIENT").getField("ID_SAISIE_VENTE_FACTURE"), null);
712
                    SQLSelectJoin joinCmd = selBadVF.addJoin("LEFT", joinTR.getJoinedTable().getField("ID_COMMANDE_CLIENT"));
721
                        SQLSelectJoin joinCmd = selBadVF.addJoin("LEFT", joinTR.getJoinedTable().getField("ID_COMMANDE_CLIENT"));
713
                    selBadVF.addSelect(joinCmd.getJoinedTable().getField("ID_AFFAIRE"));
722
                        selBadVF.addSelect(joinCmd.getJoinedTable().getField("ID_AFFAIRE"));
714
 
723
 
715
                    selBadVF.setWhere(Where.isNull(tableVF.getField("ID_AFFAIRE")));
724
                        selBadVF.setWhere(Where.isNull(tableVF.getField("ID_AFFAIRE")));
716
                    System.err.println(selBadVF.asString());
725
                        System.err.println(selBadVF.asString());
717
                    List<Object[]> result = (List<Object[]>) tableVF.getDBSystemRoot().getDataSource().executeA(selBadVF.asString());
726
                        List<Object[]> result = (List<Object[]>) tableVF.getDBSystemRoot().getDataSource().executeA(selBadVF.asString());
718
                    try {
727
                        try {
719
                        for (Object[] objects : result) {
728
                            for (Object[] objects : result) {
720
                            if (objects[2] != null && objects[2].toString().trim().length() > 0)
729
                                if (objects[2] != null && objects[2].toString().trim().length() > 0)
721
                                tableVF.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number) objects[2]).intValue()).commit();
730
                                    tableVF.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number) objects[2]).intValue()).commit();
722
                        }
731
                            }
723
                    } catch (SQLException e1) {
732
                        } catch (SQLException e1) {
724
                        // TODO Auto-generated catch block
733
                            // TODO Auto-generated catch block
725
                        e1.printStackTrace();
734
                            e1.printStackTrace();
726
                    }
735
                        }
727
                }
736
                    }
728
            }
737
                }
729
        }, MainFrame.CREATE_MENU);
738
            }, MainFrame.CREATE_MENU);
730
 
739
        }
731
        ctxt.addMenuItem(new AbstractAction("Recalcul Total achat facture prorata") {
740
        ctxt.addMenuItem(new AbstractAction("Recalcul Total achat facture prorata") {
732
            @Override
741
            @Override
733
            public void actionPerformed(ActionEvent e) {
742
            public void actionPerformed(ActionEvent e) {
734
 
743
 
735
                {
744
                {
736
                    final SQLTable table = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
745
                    final SQLTable table = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
737
                    SQLRowValues rowValsFact = new SQLRowValues(table);
746
                    SQLRowValues rowValsFact = new SQLRowValues(table);
738
                    rowValsFact.putNulls("SOLDE", "PARTIAL", "T_HA", "T_HT");
747
                    rowValsFact.putNulls("SOLDE", "PARTIAL", "T_HA", "T_HT");
739
 
748
 
740
                    final SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
749
                    final SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
741
                    SQLRowValues rowValsCmd = new SQLRowValues(tableCmd);
750
                    SQLRowValues rowValsCmd = new SQLRowValues(tableCmd);
742
                    rowValsCmd.putNulls("T_HT");
751
                    rowValsCmd.putNulls("T_HT");
743
 
752
 
744
                    final SQLTable tableCmdElt = ctxt.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
753
                    final SQLTable tableCmdElt = ctxt.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
745
                    SQLRowValues rowValsCmdElt = new SQLRowValues(tableCmdElt);
754
                    SQLRowValues rowValsCmdElt = new SQLRowValues(tableCmdElt);
746
                    rowValsCmdElt.put("ID_COMMANDE_CLIENT", rowValsCmd);
755
                    rowValsCmdElt.put("ID_COMMANDE_CLIENT", rowValsCmd);
747
                    rowValsCmdElt.putNulls("T_PA_HT", "NIVEAU");
756
                    rowValsCmdElt.putNulls("T_PA_HT", "NIVEAU");
748
 
757
 
749
                    final SQLTable tableTR = table.getTable("TR_COMMANDE_CLIENT");
758
                    final SQLTable tableTR = table.getTable("TR_COMMANDE_CLIENT");
750
                    SQLRowValues rowValsTR = new SQLRowValues(tableTR);
759
                    SQLRowValues rowValsTR = new SQLRowValues(tableTR);
751
                    rowValsTR.put("ID_SAISIE_VENTE_FACTURE", rowValsFact);
760
                    rowValsTR.put("ID_SAISIE_VENTE_FACTURE", rowValsFact);
752
                    rowValsTR.put("ID_COMMANDE_CLIENT", rowValsCmd);
761
                    rowValsTR.put("ID_COMMANDE_CLIENT", rowValsCmd);
753
 
762
 
754
                    SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsFact);
763
                    SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsFact);
755
                    fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
764
                    fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
756
                        @Override
765
                        @Override
757
                        public SQLSelect transformChecked(SQLSelect input) {
766
                        public SQLSelect transformChecked(SQLSelect input) {
758
                            Where w = new Where(table.getField("SOLDE"), "=", Boolean.TRUE);
767
                            Where w = new Where(table.getField("SOLDE"), "=", Boolean.TRUE);
759
                            w = w.or(new Where(table.getField("PARTIAL"), "=", Boolean.TRUE));
768
                            w = w.or(new Where(table.getField("PARTIAL"), "=", Boolean.TRUE));
760
                            input.setWhere(w);
769
                            input.setWhere(w);
761
                            return input;
770
                            return input;
762
                        }
771
                        }
763
                    });
772
                    });
764
 
773
 
765
                    List<SQLRowValues> rowVals = fetcher.fetch();
774
                    List<SQLRowValues> rowVals = fetcher.fetch();
766
 
775
 
767
                    for (SQLRowValues sqlRowValues : rowVals) {
776
                    for (SQLRowValues sqlRowValues : rowVals) {
768
                        // Recuperation de la commande
777
                        // Recuperation de la commande
769
                        final Collection<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableTR);
778
                        final Collection<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableTR);
770
                        if (!referentRows.isEmpty()) {
779
                        if (!referentRows.isEmpty()) {
771
                            SQLRowAccessor rowTR = referentRows.iterator().next();
780
                            SQLRowAccessor rowTR = referentRows.iterator().next();
772
                            SQLRowAccessor rowCmd = rowTR.getForeign("ID_COMMANDE_CLIENT");
781
                            SQLRowAccessor rowCmd = rowTR.getForeign("ID_COMMANDE_CLIENT");
773
                            final long htCmd = rowCmd.getLong("T_HT");
782
                            final long htCmd = rowCmd.getLong("T_HT");
774
                            if (htCmd != 0) {
783
                            if (htCmd != 0) {
775
 
784
 
776
                                BigDecimal totalHA = BigDecimal.ZERO;
785
                                BigDecimal totalHA = BigDecimal.ZERO;
777
                                Collection<? extends SQLRowAccessor> elt = rowCmd.getReferentRows(tableCmdElt);
786
                                Collection<? extends SQLRowAccessor> elt = rowCmd.getReferentRows(tableCmdElt);
778
                                for (SQLRowAccessor sqlRowAccessor : elt) {
787
                                for (SQLRowAccessor sqlRowAccessor : elt) {
779
                                    if (sqlRowAccessor.getInt("NIVEAU") == 1) {
788
                                    if (sqlRowAccessor.getInt("NIVEAU") == 1) {
780
                                        totalHA = totalHA.add(sqlRowAccessor.getBigDecimal("T_PA_HT"));
789
                                        totalHA = totalHA.add(sqlRowAccessor.getBigDecimal("T_PA_HT"));
781
                                    }
790
                                    }
782
                                }
791
                                }
783
                                BigDecimal prorata = new BigDecimal((double) sqlRowValues.getLong("T_HT") / (double) htCmd);
792
                                BigDecimal prorata = new BigDecimal((double) sqlRowValues.getLong("T_HT") / (double) htCmd);
784
                                try {
793
                                try {
785
                                    sqlRowValues.createEmptyUpdateRow().put("T_HA", totalHA.multiply(prorata).movePointRight(2).setScale(0, RoundingMode.HALF_UP).longValue()).update();
794
                                    sqlRowValues.createEmptyUpdateRow().put("T_HA", totalHA.multiply(prorata).movePointRight(2).setScale(0, RoundingMode.HALF_UP).longValue()).update();
786
                                } catch (SQLException e1) {
795
                                } catch (SQLException e1) {
787
                                    e1.printStackTrace();
796
                                    e1.printStackTrace();
788
                                }
797
                                }
789
                            }
798
                            }
790
                        }
799
                        }
791
                    }
800
                    }
792
                }
801
                }
793
            }
802
            }
794
        }, MainFrame.CREATE_MENU);
803
        }, MainFrame.CREATE_MENU);
795
    }
804
    }
796
 
805
 
797
    @Override
806
    @Override
798
    protected void start() {
807
    protected void start() {
799
 
808
 
800
        final JComponent quoteComponent = createQuotePanel();
809
        final JComponent quoteComponent = createQuotePanel();
801
        final JComponent orderComponent = createOrderPanel();
810
        final JComponent orderComponent = createOrderPanel();
802
        MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
811
        MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
803
        MainFrame.getInstance().getTabbedPane().addTab("Devis en attente", quoteComponent);
812
        MainFrame.getInstance().getTabbedPane().addTab("Devis en attente", quoteComponent);
804
        MainFrame.getInstance().getTabbedPane().addTab("Affaires", new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(PROJECT_TABLENAME)));
813
        MainFrame.getInstance().getTabbedPane().addTab("Affaires", new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(PROJECT_TABLENAME)));
805
        // Fix for classic XP Theme
814
        // Fix for classic XP Theme
806
        quoteComponent.setOpaque(true);
815
        quoteComponent.setOpaque(true);
807
        quoteComponent.setBackground(Color.WHITE);
816
        quoteComponent.setBackground(Color.WHITE);
808
        orderComponent.setOpaque(true);
817
        orderComponent.setOpaque(true);
809
        orderComponent.setBackground(Color.WHITE);
818
        orderComponent.setBackground(Color.WHITE);
810
        // Select first tab
819
        // Select first tab
811
        MainFrame.getInstance().getTabbedPane().setSelectedIndex(1);
820
        MainFrame.getInstance().getTabbedPane().setSelectedIndex(1);
812
 
821
 
813
        CommandeClientItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
822
        CommandeClientItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
814
        SaisieVenteFactureItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
823
        SaisieVenteFactureItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
815
        AccountingRecordsProvider p = new AccountingRecordsProvider() {
824
        AccountingRecordsProvider p = new AccountingRecordsProvider() {
816
 
825
 
817
            @Override
826
            @Override
818
            public void putLabel(SQLRowAccessor rowSource, Map<String, Object> values) {
827
            public void putLabel(SQLRowAccessor rowSource, Map<String, Object> values) {
819
                values.put("NOM", "Fact. vente " + rowSource.getString("NUMERO"));
828
                values.put("NOM", "Fact. vente " + rowSource.getString("NUMERO"));
820
            }
829
            }
821
 
830
 
822
            @Override
831
            @Override
823
            public void putPieceLabel(SQLRowAccessor rowSource, SQLRowValues rowValsPiece) {
832
            public void putPieceLabel(SQLRowAccessor rowSource, SQLRowValues rowValsPiece) {
824
                rowValsPiece.put("NOM", rowSource.getString("NUMERO"));
833
                rowValsPiece.put("NOM", rowSource.getString("NUMERO"));
825
            }
834
            }
826
        };
835
        };
827
        AccountingRecordsProviderManager.put(GenerationMvtSaisieVenteFacture.ID, p);
836
        AccountingRecordsProviderManager.put(GenerationMvtSaisieVenteFacture.ID, p);
828
 
837
 
829
        final SQLTable tableFact = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable("SAISIE_VENTE_FACTURE");
838
        final SQLTable tableFact = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable("SAISIE_VENTE_FACTURE");
830
 
839
 
831
        tableFact.addTableModifiedListener(new SQLTableModifiedListener() {
840
        tableFact.addTableModifiedListener(new SQLTableModifiedListener() {
832
 
841
 
833
            @Override
842
            @Override
834
            public void tableModified(SQLTableEvent evt) {
843
            public void tableModified(SQLTableEvent evt) {
835
                if (evt.getMode() == Mode.ROW_ADDED || evt.getMode() == Mode.ROW_UPDATED) {
844
                if (evt.getMode() == Mode.ROW_ADDED || evt.getMode() == Mode.ROW_UPDATED) {
836
                    checkProjectState(evt.getRow());
845
                    checkProjectState(evt.getRow());
837
                }
846
                }
838
            }
847
            }
839
        });
848
        });
840
    }
849
    }
841
 
850
 
842
    private JComponent createQuotePanel() {
851
    private JComponent createQuotePanel() {
843
        ColumnRowRenderer cRenderer = new QuoteColumnRowRenderer();
852
        ColumnRowRenderer cRenderer = new QuoteColumnRowRenderer();
844
        ColumnFooterRenderer fRenderer = new QuoteColumnFooterRenderer();
853
        ColumnFooterRenderer fRenderer = new QuoteColumnFooterRenderer();
845
        final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
854
        final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
846
        columnPanel.setOpaque(false);
855
        columnPanel.setOpaque(false);
847
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
856
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
848
        Path p = Path.get(element.getTable()).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
857
        Path p = Path.get(element.getTable()).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
849
 
858
 
850
        SQLRowValues values = new SQLRowValues(element.getTable());
859
        SQLRowValues values = new SQLRowValues(element.getTable());
851
        values.put("NOM", null);
860
        values.put("NOM", null);
852
        values.put("T_PV_HT", null);
861
        values.put("T_PV_HT", null);
853
        SQLRowValues rowValsClient = new SQLRowValues(element.getTable().getTable("CLIENT"));
862
        SQLRowValues rowValsClient = new SQLRowValues(element.getTable().getTable("CLIENT"));
854
        rowValsClient.put("NOM", null);
863
        rowValsClient.put("NOM", null);
855
        final SQLTable tableDevis = element.getTable().getTable("DEVIS");
864
        final SQLTable tableDevis = element.getTable().getTable("DEVIS");
856
        SQLRowValues rowValsDevis = new SQLRowValues(tableDevis);
865
        SQLRowValues rowValsDevis = new SQLRowValues(tableDevis);
857
        rowValsDevis.put("NUMERO", null);
866
        rowValsDevis.put("NUMERO", null);
858
        rowValsDevis.put("DATE", null);
867
        rowValsDevis.put("DATE", null);
859
        rowValsDevis.put("T_HT", null);
868
        rowValsDevis.put("T_HT", null);
860
 
869
 
861
        rowValsDevis.put("ID_CLIENT", rowValsClient);
870
        rowValsDevis.put("ID_CLIENT", rowValsClient);
862
        values.put("ID_DEVIS", rowValsDevis);
871
        values.put("ID_DEVIS", rowValsDevis);
863
        SQLRowValues rowValsUnite = new SQLRowValues(element.getTable().getTable("UNITE_VENTE"));
872
        SQLRowValues rowValsUnite = new SQLRowValues(element.getTable().getTable("UNITE_VENTE"));
864
        rowValsUnite.put("CODE", null);
873
        rowValsUnite.put("CODE", null);
865
        values.put("ID_UNITE_VENTE", rowValsUnite);
874
        values.put("ID_UNITE_VENTE", rowValsUnite);
866
        values.put("QTE", null);
875
        values.put("QTE", null);
867
        values.put("QTE_UNITAIRE", null);
876
        values.put("QTE_UNITAIRE", null);
868
 
877
 
869
        ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
878
        ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
870
            @Override
879
            @Override
871
            public SQLSelect transformChecked(SQLSelect input) {
880
            public SQLSelect transformChecked(SQLSelect input) {
872
                input.andWhere(new Where(input.getAlias(tableDevis.getField("ID_ETAT_DEVIS")), "=", EtatDevisSQLElement.EN_ATTENTE));
881
                input.andWhere(new Where(input.getAlias(tableDevis.getField("ID_ETAT_DEVIS")), "=", EtatDevisSQLElement.EN_ATTENTE));
873
                return input;
882
                return input;
874
            }
883
            }
875
        };
884
        };
876
        final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
885
        final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
877
        columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
886
        columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
878
        columnPanel.setFetch(projectFetcher);
887
        columnPanel.setFetch(projectFetcher);
879
 
888
 
880
        final JScrollPane comp = new JScrollPane(columnPanel);
889
        final JScrollPane comp = new JScrollPane(columnPanel);
881
        comp.setBorder(null);
890
        comp.setBorder(null);
882
        comp.getViewport().setOpaque(false);
891
        comp.getViewport().setOpaque(false);
883
        return comp;
892
        return comp;
884
    }
893
    }
885
 
894
 
886
    private JComponent createOrderPanel() {
895
    private JComponent createOrderPanel() {
887
        ColumnRowRenderer cRenderer = new OrderColumnRowRenderer();
896
        ColumnRowRenderer cRenderer = new OrderColumnRowRenderer();
888
        ColumnFooterRenderer fRenderer = new OrderColumnFooterRenderer();
897
        ColumnFooterRenderer fRenderer = new OrderColumnFooterRenderer();
889
        final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
898
        final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
890
        columnPanel.setOpaque(false);
899
        columnPanel.setOpaque(false);
891
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
900
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
892
        final SQLTable tableOrder = element.getTable();
901
        final SQLTable tableOrder = element.getTable();
893
        Path p = Path.get(tableOrder).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
902
        Path p = Path.get(tableOrder).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
894
 
903
 
895
        SQLRowValues values = new SQLRowValues(tableOrder);
904
        SQLRowValues values = new SQLRowValues(tableOrder);
896
        values.put("NOM", null);
905
        values.put("NOM", null);
897
        values.put("T_PV_HT", null);
906
        values.put("T_PV_HT", null);
898
        SQLRowValues rowValsClient = new SQLRowValues(tableOrder.getTable("CLIENT"));
907
        SQLRowValues rowValsClient = new SQLRowValues(tableOrder.getTable("CLIENT"));
899
        rowValsClient.put("NOM", null);
908
        rowValsClient.put("NOM", null);
900
        SQLRowValues rowValsCmd = new SQLRowValues(tableOrder.getTable("COMMANDE_CLIENT"));
909
        SQLRowValues rowValsCmd = new SQLRowValues(tableOrder.getTable("COMMANDE_CLIENT"));
901
        rowValsCmd.put("NUMERO", null);
910
        rowValsCmd.put("NUMERO", null);
902
        rowValsCmd.put("DATE", null);
911
        rowValsCmd.put("DATE", null);
903
        rowValsCmd.put("T_HT", null);
912
        rowValsCmd.put("T_HT", null);
904
 
913
 
905
        rowValsCmd.put("ID_CLIENT", rowValsClient);
914
        rowValsCmd.put("ID_CLIENT", rowValsClient);
906
        values.put("ID_COMMANDE_CLIENT", rowValsCmd);
915
        values.put("ID_COMMANDE_CLIENT", rowValsCmd);
907
        SQLRowValues rowValsUnite = new SQLRowValues(tableOrder.getTable("UNITE_VENTE"));
916
        SQLRowValues rowValsUnite = new SQLRowValues(tableOrder.getTable("UNITE_VENTE"));
908
        rowValsUnite.put("CODE", null);
917
        rowValsUnite.put("CODE", null);
909
        values.put("ID_UNITE_VENTE", rowValsUnite);
918
        values.put("ID_UNITE_VENTE", rowValsUnite);
910
        values.put("QTE", null);
919
        values.put("QTE", null);
911
        values.put("QTE_UNITAIRE", null);
920
        values.put("QTE_UNITAIRE", null);
912
 
921
 
913
        final SQLTable tableAffaire = tableOrder.getTable(PROJECT_TABLENAME);
922
        final SQLTable tableAffaire = tableOrder.getTable(PROJECT_TABLENAME);
914
        SQLRowValues rowValsAffaire = new SQLRowValues(tableAffaire);
923
        SQLRowValues rowValsAffaire = new SQLRowValues(tableAffaire);
915
        rowValsAffaire.put("NUMERO", null);
924
        rowValsAffaire.put("NUMERO", null);
916
        rowValsAffaire.put("DATE", null);
925
        rowValsAffaire.put("DATE", null);
917
        rowValsCmd.put("ID_AFFAIRE", rowValsAffaire);
926
        rowValsCmd.put("ID_AFFAIRE", rowValsAffaire);
918
 
927
 
919
        if (tableOrder.getDBRoot().contains("AFFAIRE_TEMPS")) {
928
        if (tableOrder.getDBRoot().contains("AFFAIRE_TEMPS")) {
920
            final SQLTable tableAffaireTemps = tableOrder.getTable("AFFAIRE_TEMPS");
929
            final SQLTable tableAffaireTemps = tableOrder.getTable("AFFAIRE_TEMPS");
921
            SQLRowValues rowValsAffaireTemps = new SQLRowValues(tableAffaireTemps);
930
            SQLRowValues rowValsAffaireTemps = new SQLRowValues(tableAffaireTemps);
922
            rowValsAffaireTemps.put("TEMPS", null);
931
            rowValsAffaireTemps.put("TEMPS", null);
923
            rowValsAffaireTemps.put("ID_COMMANDE_CLIENT_ELEMENT", values);
932
            rowValsAffaireTemps.put("ID_COMMANDE_CLIENT_ELEMENT", values);
924
        }
933
        }
925
        ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
934
        ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
926
            @Override
935
            @Override
927
            public SQLSelect transformChecked(SQLSelect input) {
936
            public SQLSelect transformChecked(SQLSelect input) {
928
                input.andWhere(new Where(input.getAlias(tableAffaire.getField("ID_ETAT_AFFAIRE")), "=", ProjectStateSQLElement.EN_COURS));
937
                input.andWhere(new Where(input.getAlias(tableAffaire.getField("ID_ETAT_AFFAIRE")), "=", ProjectStateSQLElement.EN_COURS));
929
                return input;
938
                return input;
930
            }
939
            }
931
        };
940
        };
932
        final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
941
        final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
933
        columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
942
        columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
934
        columnPanel.setFetch(projectFetcher);
943
        columnPanel.setFetch(projectFetcher);
935
        final JScrollPane comp = new JScrollPane(columnPanel);
944
        final JScrollPane comp = new JScrollPane(columnPanel);
936
        comp.setBorder(null);
945
        comp.setBorder(null);
937
        comp.getViewport().setOpaque(false);
946
        comp.getViewport().setOpaque(false);
938
        return comp;
947
        return comp;
939
    }
948
    }
940
 
949
 
941
    @Override
950
    @Override
942
    protected void stop() {
951
    protected void stop() {
943
    }
952
    }
944
}
953
}