OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Rev 90 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 83
Line 14... Line 14...
14
 package org.openconcerto.erp.core.sales.invoice.component;
14
 package org.openconcerto.erp.core.sales.invoice.component;
15
 
15
 
16
import static org.openconcerto.utils.CollectionUtils.createSet;
16
import static org.openconcerto.utils.CollectionUtils.createSet;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
-
 
19
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
20
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
20
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
21
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
21
import org.openconcerto.erp.core.common.ui.AbstractArticleItemTable;
22
import org.openconcerto.erp.core.common.ui.AbstractArticleItemTable;
22
import org.openconcerto.erp.core.common.ui.DeviseField;
23
import org.openconcerto.erp.core.common.ui.DeviseField;
23
import org.openconcerto.erp.core.common.ui.TotalPanel;
24
import org.openconcerto.erp.core.common.ui.TotalPanel;
Line 26... Line 27...
26
import org.openconcerto.erp.core.finance.payment.component.ModeDeReglementSQLComponent;
27
import org.openconcerto.erp.core.finance.payment.component.ModeDeReglementSQLComponent;
27
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
28
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
28
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
29
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
29
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
30
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
30
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
31
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
31
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
32
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
-
 
33
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.Type;
32
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
34
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
33
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
35
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
34
import org.openconcerto.erp.model.BanqueModifiedListener;
36
import org.openconcerto.erp.model.BanqueModifiedListener;
35
import org.openconcerto.erp.model.ISQLCompteSelector;
37
import org.openconcerto.erp.model.ISQLCompteSelector;
36
import org.openconcerto.erp.panel.PanelOOSQLComponent;
38
import org.openconcerto.erp.panel.PanelOOSQLComponent;
37
import org.openconcerto.erp.preferences.DefaultNXProps;
39
import org.openconcerto.erp.preferences.DefaultNXProps;
38
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
40
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
39
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
41
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
40
import org.openconcerto.sql.Configuration;
42
import org.openconcerto.sql.Configuration;
41
import org.openconcerto.sql.element.ElementSQLObject;
43
import org.openconcerto.sql.element.ElementSQLObject;
-
 
44
import org.openconcerto.sql.element.SQLComponent;
42
import org.openconcerto.sql.element.SQLElement;
45
import org.openconcerto.sql.element.SQLElement;
43
import org.openconcerto.sql.model.SQLBackgroundTableCache;
46
import org.openconcerto.sql.model.SQLBackgroundTableCache;
44
import org.openconcerto.sql.model.SQLBase;
47
import org.openconcerto.sql.model.SQLBase;
45
import org.openconcerto.sql.model.SQLInjector;
48
import org.openconcerto.sql.model.SQLInjector;
46
import org.openconcerto.sql.model.SQLRow;
49
import org.openconcerto.sql.model.SQLRow;
Line 50... Line 53...
50
import org.openconcerto.sql.model.SQLTable;
53
import org.openconcerto.sql.model.SQLTable;
51
import org.openconcerto.sql.model.UndefinedRowValuesCache;
54
import org.openconcerto.sql.model.UndefinedRowValuesCache;
52
import org.openconcerto.sql.model.Where;
55
import org.openconcerto.sql.model.Where;
53
import org.openconcerto.sql.preferences.SQLPreferences;
56
import org.openconcerto.sql.preferences.SQLPreferences;
54
import org.openconcerto.sql.sqlobject.ElementComboBox;
57
import org.openconcerto.sql.sqlobject.ElementComboBox;
55
import org.openconcerto.sql.sqlobject.ISQLElementWithCodeSelector;
-
 
56
import org.openconcerto.sql.sqlobject.JUniqueTextField;
58
import org.openconcerto.sql.sqlobject.JUniqueTextField;
57
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
59
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
58
import org.openconcerto.sql.sqlobject.SQLTextCombo;
60
import org.openconcerto.sql.sqlobject.SQLTextCombo;
59
import org.openconcerto.sql.users.UserManager;
61
import org.openconcerto.sql.users.UserManager;
60
import org.openconcerto.sql.view.EditFrame;
62
import org.openconcerto.sql.view.EditFrame;
Line 65... Line 67...
65
import org.openconcerto.ui.JDate;
67
import org.openconcerto.ui.JDate;
66
import org.openconcerto.ui.TitledSeparator;
68
import org.openconcerto.ui.TitledSeparator;
67
import org.openconcerto.ui.component.ITextArea;
69
import org.openconcerto.ui.component.ITextArea;
68
import org.openconcerto.utils.ExceptionHandler;
70
import org.openconcerto.utils.ExceptionHandler;
69
import org.openconcerto.utils.GestionDevise;
71
import org.openconcerto.utils.GestionDevise;
-
 
72
import org.openconcerto.utils.ProductInfo;
70
import org.openconcerto.utils.text.SimpleDocumentListener;
73
import org.openconcerto.utils.text.SimpleDocumentListener;
71
 
74
 
72
import java.awt.GridBagConstraints;
75
import java.awt.GridBagConstraints;
73
import java.awt.GridBagLayout;
76
import java.awt.GridBagLayout;
74
import java.awt.event.ActionEvent;
77
import java.awt.event.ActionEvent;
Line 113... Line 116...
113
    private ElementComboBox selAvoir, selAffaire;
116
    private ElementComboBox selAvoir, selAffaire;
114
    private ElementSQLObject eltModeRegl;
117
    private ElementSQLObject eltModeRegl;
115
    private static final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
118
    private static final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
116
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
119
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
117
    private static final SQLRow rowPrefsCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte).getRowFromId(2);
120
    private static final SQLRow rowPrefsCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte).getRowFromId(2);
118
    private ISQLElementWithCodeSelector contact;
121
    private ElementComboBox contact;
119
    private SQLRowAccessor rowSelected;
122
    private SQLRowAccessor rowSelected;
120
    private SQLElement eltContact = Configuration.getInstance().getDirectory().getElement("CONTACT");
123
    private SQLElement eltContact = Configuration.getInstance().getDirectory().getElement("CONTACT");
121
    private JTextField refClient = new JTextField();
124
    private JTextField refClient = new JTextField();
122
    private SQLRowValues defaultContactRowValues = new SQLRowValues(this.eltContact.getTable());
125
    private SQLRowValues defaultContactRowValues = new SQLRowValues(this.eltContact.getTable());
123
    protected TotalPanel totalTTC;
126
    protected TotalPanel totalTTC;
Line 125... Line 128...
125
    private SQLTextCombo textTypeMission = new SQLTextCombo();
128
    private SQLTextCombo textTypeMission = new SQLTextCombo();
126
 
129
 
127
    private PropertyChangeListener listenerModeReglDefaut = new PropertyChangeListener() {
130
    private PropertyChangeListener listenerModeReglDefaut = new PropertyChangeListener() {
128
        public void propertyChange(PropertyChangeEvent arg0) {
131
        public void propertyChange(PropertyChangeEvent arg0) {
129
 
132
 
130
            int idCli = SaisieVenteFactureSQLComponent.this.comboClient.getSelectedId();
133
            int idCli = SaisieVenteFactureSQLComponent.this.comboClient.getWantedID();
131
            if (idCli > 1) {
134
            if (idCli > 1) {
132
                SQLRow rowCli = SaisieVenteFactureSQLComponent.this.client.getTable().getRow(idCli);
135
                SQLRow rowCli = SaisieVenteFactureSQLComponent.this.client.getTable().getRow(idCli);
133
 
136
 
134
                if (SaisieVenteFactureSQLComponent.this.rowSelected == null || SaisieVenteFactureSQLComponent.this.rowSelected.getID() <= 1
-
 
135
                        || SaisieVenteFactureSQLComponent.this.rowSelected.getInt("ID_CLIENT") != idCli) {
137
                if (getMode() == SQLComponent.Mode.INSERTION || !isFilling()) {
136
                    SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
138
                    SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
137
                    int idModeRegl = rowCli.getInt("ID_MODE_REGLEMENT");
139
                    int idModeRegl = rowCli.getInt("ID_MODE_REGLEMENT");
138
                    if (idModeRegl > 1) {
140
                    if (idModeRegl > 1) {
139
                        SQLRow rowModeRegl = sqleltModeRegl.getTable().getRow(idModeRegl);
141
                        SQLRow rowModeRegl = sqleltModeRegl.getTable().getRow(idModeRegl);
140
                        SQLRowValues rowValsModeRegl = rowModeRegl.createUpdateRow();
142
                        SQLRowValues rowValsModeRegl = rowModeRegl.createUpdateRow();
Line 145... Line 147...
145
            }
147
            }
146
            Where w = new Where(SaisieVenteFactureSQLComponent.this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE);
148
            Where w = new Where(SaisieVenteFactureSQLComponent.this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE);
147
            if (SaisieVenteFactureSQLComponent.this.comboClient.isEmpty()) {
149
            if (SaisieVenteFactureSQLComponent.this.comboClient.isEmpty()) {
148
                w = w.and(new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", -1));
150
                w = w.and(new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", -1));
149
            } else {
151
            } else {
150
                w = w.and(new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", SaisieVenteFactureSQLComponent.this.comboClient.getSelectedId()));
152
                w = w.and(new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", idCli));
151
            }
153
            }
152
            if (getSelectedID() > 1) {
154
            if (getSelectedID() > 1) {
153
                SQLRow row = getTable().getRow(getSelectedID());
155
                SQLRow row = getTable().getRow(getSelectedID());
154
                w = w.or(new Where(SaisieVenteFactureSQLComponent.this.tableAvoir.getKey(), "=", row.getInt("ID_AVOIR_CLIENT")));
156
                w = w.or(new Where(SaisieVenteFactureSQLComponent.this.tableAvoir.getKey(), "=", row.getInt("ID_AVOIR_CLIENT")));
155
            }
157
            }
Line 163... Line 165...
163
    private PropertyChangeListener changeClientListener;
165
    private PropertyChangeListener changeClientListener;
164
    private ISQLCompteSelector compteSelService;
166
    private ISQLCompteSelector compteSelService;
165
    private JLabel labelCompteServ;
167
    private JLabel labelCompteServ;
166
    private ElementComboBox comboCommercial;
168
    private ElementComboBox comboCommercial;
167
    private ElementComboBox comboVerificateur = new ElementComboBox();;
169
    private ElementComboBox comboVerificateur = new ElementComboBox();;
-
 
170
    private SQLTable tableBanque = getTable().getTable(BanqueSQLElement.TABLENAME);
168
 
171
 
169
 
172
 
170
    public SaisieVenteFactureSQLComponent() {
173
    public SaisieVenteFactureSQLComponent() {
171
        super(Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE"));
174
        super(Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE"));
-
 
175
 
172
    }
176
    }
173
 
177
 
174
 
178
 
175
    private int previousClient = -1;
179
    private int previousClient = -1;
176
 
180
 
Line 195... Line 199...
195
        this.add(addP, c);
199
        this.add(addP, c);
196
 
200
 
197
        c.gridy++;
201
        c.gridy++;
198
        c.gridwidth = 1;
202
        c.gridwidth = 1;
199
 
203
 
-
 
204
 
-
 
205
            if (getTable().contains("ID_POLE_PRODUIT")) {
-
 
206
                JLabel labelPole = new JLabel(getLabelFor("ID_POLE_PRODUIT"));
-
 
207
                labelPole.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
208
                this.add(labelPole, c);
-
 
209
                c.gridx++;
-
 
210
                ElementComboBox pole = new ElementComboBox();
-
 
211
 
-
 
212
                this.add(pole, c);
-
 
213
                this.addSQLObject(pole, "ID_POLE_PRODUIT");
-
 
214
                c.gridy++;
-
 
215
                c.gridwidth = 1;
-
 
216
                c.gridx = 0;
-
 
217
            }
-
 
218
 
200
        /*******************************************************************************************
219
        /*******************************************************************************************
201
         * * RENSEIGNEMENTS
220
         * * RENSEIGNEMENTS
202
         ******************************************************************************************/
221
         ******************************************************************************************/
203
        // Ligne 1 : Numero de facture
222
        // Ligne 1 : Numero de facture
204
        JLabel labelNum = new JLabel(getLabelFor("NUMERO"));
223
        JLabel labelNum = new JLabel(getLabelFor("NUMERO"));
Line 363... Line 382...
363
        c.gridwidth = GridBagConstraints.REMAINDER;
382
        c.gridwidth = GridBagConstraints.REMAINDER;
364
        // this.add(this.checkAcompte, c);
383
        // this.add(this.checkAcompte, c);
365
        c.gridwidth = 1;
384
        c.gridwidth = 1;
366
        this.addView(this.checkAcompte, "ACOMPTE");
385
        this.addView(this.checkAcompte, "ACOMPTE");
367
 
386
 
368
        Boolean bCompteCli = Boolean.valueOf(DefaultNXProps.getInstance().getStringProperty("HideCompteFacture"));
-
 
369
        if (!bCompteCli) {
-
 
370
            // Ligne 5: Compte Client
-
 
371
            c.gridy++;
-
 
372
            c.gridx = 0;
-
 
373
            c.fill = GridBagConstraints.HORIZONTAL;
-
 
374
            c.gridwidth = 1;
-
 
375
            c.weightx = 0;
-
 
376
            this.add(new JLabel("Compte", SwingConstants.RIGHT), c);
-
 
377
 
-
 
378
            c.gridx++;
-
 
379
            c.weightx = 1;
-
 
380
            this.compteSel = new ISQLCompteSelector();
-
 
381
            this.compteSel.init();
-
 
382
            c.gridwidth = 3;
-
 
383
            this.add(this.compteSel, c);
-
 
384
            this.compteSel.addValueListener(this.changeCompteListener);
-
 
385
 
-
 
386
        }
-
 
387
 
-
 
388
 
-
 
389
        // Compte Service
387
        // Compte Service
390
        this.checkCompteServiceAuto = new JCheckBox(getLabelFor("COMPTE_SERVICE_AUTO"));
388
        this.checkCompteServiceAuto = new JCheckBox(getLabelFor("COMPTE_SERVICE_AUTO"));
391
        this.addSQLObject(this.checkCompteServiceAuto, "COMPTE_SERVICE_AUTO");
389
        this.addSQLObject(this.checkCompteServiceAuto, "COMPTE_SERVICE_AUTO");
392
        this.compteSelService = new ISQLCompteSelector();
390
        this.compteSelService = new ISQLCompteSelector();
393
 
391
 
Line 412... Line 410...
412
            public void actionPerformed(ActionEvent e) {
410
            public void actionPerformed(ActionEvent e) {
413
                setCompteServiceVisible(!SaisieVenteFactureSQLComponent.this.checkCompteServiceAuto.isSelected());
411
                setCompteServiceVisible(!SaisieVenteFactureSQLComponent.this.checkCompteServiceAuto.isSelected());
414
            }
412
            }
415
        });
413
        });
416
 
414
 
-
 
415
        // FIXME A checker si utile pour Preventec ou KD
-
 
416
        setCompteServiceVisible(false);
417
        setCompteServiceVisible(!(bServ != null && !bServ.booleanValue()));
417
        // setCompteServiceVisible(!(bServ != null && !bServ.booleanValue()));
418
 
418
 
419
 
419
 
420
        final JPanel pAcompte = new JPanel();
420
        final JPanel pAcompte = new JPanel();
421
        final DeviseField textAcompteHT = new DeviseField();
421
        final DeviseField textAcompteHT = new DeviseField();
422
        pAcompte.add(new JLabel("Acompte HT"));
422
        pAcompte.add(new JLabel("Acompte HT"));
Line 453... Line 453...
453
            this.add(new JLabel("Tarif à appliquer", SwingConstants.RIGHT), c);
453
            this.add(new JLabel("Tarif à appliquer", SwingConstants.RIGHT), c);
454
            c.gridx++;
454
            c.gridx++;
455
            c.gridwidth = GridBagConstraints.REMAINDER;
455
            c.gridwidth = GridBagConstraints.REMAINDER;
456
            c.fill = GridBagConstraints.NONE;
456
            c.fill = GridBagConstraints.NONE;
457
            c.weightx = 1;
457
            c.weightx = 1;
-
 
458
            DefaultGridBagConstraints.lockMinimumSize(boxTarif);
458
            this.add(boxTarif, c);
459
            this.add(boxTarif, c);
459
            this.addView(boxTarif, "ID_TARIF");
460
            this.addView(boxTarif, "ID_TARIF");
460
            boxTarif.addModelListener("wantedID", new PropertyChangeListener() {
461
            boxTarif.addModelListener("wantedID", new PropertyChangeListener() {
461
 
462
 
462
                @Override
463
                @Override
Line 634... Line 635...
634
        this.addSQLObject(infos, "INFOS");
635
        this.addSQLObject(infos, "INFOS");
635
        this.addSQLObject(this.checkPrevisionnelle, "PREVISIONNELLE");
636
        this.addSQLObject(this.checkPrevisionnelle, "PREVISIONNELLE");
636
        this.addSQLObject(this.checkComplement, "COMPLEMENT");
637
        this.addSQLObject(this.checkComplement, "COMPLEMENT");
637
        this.addSQLObject(this.selAvoir, "ID_AVOIR_CLIENT");
638
        this.addSQLObject(this.selAvoir, "ID_AVOIR_CLIENT");
638
        this.addSQLObject(this.compteSelService, "ID_COMPTE_PCE_SERVICE");
639
        this.addSQLObject(this.compteSelService, "ID_COMPTE_PCE_SERVICE");
639
        final SQLTable tableBanque;
-
 
640
        ModeDeReglementSQLComponent modeReglComp;
640
        ModeDeReglementSQLComponent modeReglComp;
-
 
641
 
641
        modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild();
642
        modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild();
642
        this.selAvoir.getRequest().setWhere(new Where(this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE));
643
        this.selAvoir.getRequest().setWhere(new Where(this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE));
643
        this.selAvoir.fillCombo();
644
        this.selAvoir.fillCombo();
644
 
645
 
645
        // Selection du compte de service
646
        // Selection du compte de service
Line 689... Line 690...
689
        this.changeClientListener = new PropertyChangeListener() {
690
        this.changeClientListener = new PropertyChangeListener() {
690
 
691
 
691
            public void propertyChange(PropertyChangeEvent evt) {
692
            public void propertyChange(PropertyChangeEvent evt) {
692
 
693
 
693
                if (SaisieVenteFactureSQLComponent.this.comboClient.getValue() != null) {
694
                if (SaisieVenteFactureSQLComponent.this.comboClient.getValue() != null) {
694
                    Integer id = SaisieVenteFactureSQLComponent.this.comboClient.getValue();
695
                    final SQLRow row = SaisieVenteFactureSQLComponent.this.comboClient.getSelectedRow();
695
 
-
 
696
                    SaisieVenteFactureSQLComponent.this.defaultContactRowValues.put("ID_CLIENT", id);
-
 
697
                    if (id > 1) {
-
 
698
 
-
 
699
                        SQLRow row = SaisieVenteFactureSQLComponent.this.client.getTable().getRow(id);
696
                    final int id = row == null ? SQLRow.NONEXISTANT_ID : row.getID();
700
 
697
 
-
 
698
                    SaisieVenteFactureSQLComponent.this.defaultContactRowValues.putForeignID("ID_CLIENT", row);
-
 
699
                    if (row != null) {
701
                        if (SaisieVenteFactureSQLComponent.this.contact != null) {
700
                        if (SaisieVenteFactureSQLComponent.this.contact != null) {
702
                            Where w = new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", SQLRow.NONEXISTANT_ID);
701
                            Where w = new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", SQLRow.NONEXISTANT_ID);
703
                                w = w.or(new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", id));
702
                                w = w.or(new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", id));
704
                            SaisieVenteFactureSQLComponent.this.contact.setWhereOnRequest(w);
703
                            SaisieVenteFactureSQLComponent.this.contact.getRequest().setWhere(w);
705
                        }
704
                        }
706
                            if (SaisieVenteFactureSQLComponent.this.comboAdresse != null) {
705
                            if (SaisieVenteFactureSQLComponent.this.comboAdresse != null) {
707
 
706
 
708
                                Where w = new Where(SaisieVenteFactureSQLComponent.TABLE_ADRESSE.getKey(), "=", row.getInt("ID_ADRESSE"));
707
                                Where w = new Where(SaisieVenteFactureSQLComponent.TABLE_ADRESSE.getKey(), "=", row.getInt("ID_ADRESSE"));
709
 
708
 
Line 746... Line 745...
746
                        }
745
                        }
747
                    }
746
                    }
748
                }
747
                }
749
            }
748
            }
750
        };
749
        };
-
 
750
 
751
        this.textPortHT.getDocument().addDocumentListener(new SimpleDocumentListener() {
751
        this.textPortHT.getDocument().addDocumentListener(new SimpleDocumentListener() {
752
            @Override
752
            @Override
753
            public void update(DocumentEvent e) {
753
            public void update(DocumentEvent e) {
754
                totalTTC.updateTotal();
754
                totalTTC.updateTotal();
755
            }
755
            }
Line 766... Line 766...
766
            public void propertyChange(PropertyChangeEvent evt) {
766
            public void propertyChange(PropertyChangeEvent evt) {
767
                if (SaisieVenteFactureSQLComponent.this.isFilling())
767
                if (SaisieVenteFactureSQLComponent.this.isFilling())
768
                    return;
768
                    return;
769
                final SQLRow row = ((SQLRequestComboBox) evt.getSource()).getSelectedRow();
769
                final SQLRow row = ((SQLRequestComboBox) evt.getSource()).getSelectedRow();
770
                if (row != null) {
770
                if (row != null) {
771
                    SaisieVenteFactureSQLComponent.this.defaultContactRowValues.put("ID_CLIENT", row.getIDNumber());
771
                    SaisieVenteFactureSQLComponent.this.defaultContactRowValues.putForeignID("ID_CLIENT", row);
772
                    if (SaisieVenteFactureSQLComponent.this.client.getTable().contains("ID_TARIF")) {
772
                    if (SaisieVenteFactureSQLComponent.this.client.getTable().contains("ID_TARIF")) {
773
                        SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
773
                        SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
774
                        if (foreignRow != null && !foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
774
                        if (foreignRow != null && !foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
775
                                && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associés au client?") == JOptionPane.YES_OPTION) {
775
                                && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associés au client?") == JOptionPane.YES_OPTION) {
776
                            boxTarif.setValue(foreignRow.getID());
776
                            boxTarif.setValue(foreignRow.getID());
Line 803... Line 803...
803
                    }
803
                    }
804
                }
804
                }
805
 
805
 
806
            }
806
            }
807
        });
807
        });
-
 
808
 
808
    }
809
    }
809
 
810
 
810
    private JPanel createPanelAvoir() {
811
    private JPanel createPanelAvoir() {
811
        JPanel panelAvoir = new JPanel(new GridBagLayout());
812
        JPanel panelAvoir = new JPanel(new GridBagLayout());
812
        panelAvoir.setOpaque(false);
813
        panelAvoir.setOpaque(false);
Line 911... Line 912...
911
        }
912
        }
912
 
913
 
913
        if (compteSel != null) {
914
        if (compteSel != null) {
914
            this.compteSel.rmValueListener(this.changeCompteListener);
915
            this.compteSel.rmValueListener(this.changeCompteListener);
915
        }
916
        }
-
 
917
        if (getMode() != Mode.INSERTION) {
916
        if (this.comboClient != null)
918
            if (this.comboClient != null)
917
            this.comboClient.rmValueListener(this.listenerModeReglDefaut);
919
                this.comboClient.rmValueListener(this.listenerModeReglDefaut);
-
 
920
        }
918
        this.rowSelected = r;
921
        this.rowSelected = r;
919
        if (r != null) {
922
        if (r != null) {
920
            this.textNumeroUnique.setIdSelected(r.getID());
923
            this.textNumeroUnique.setIdSelected(r.getID());
-
 
924
 
-
 
925
            // FIXME Mettre un droit pour autoriser la modification d'une facture lettrée ou pointée
921
            if (!r.isUndefined() && r.getObject("ID_MOUVEMENT") != null && !r.isForeignEmpty("ID_MOUVEMENT")) {
926
            if (!r.isUndefined() && r.getObject("ID_MOUVEMENT") != null && !r.isForeignEmpty("ID_MOUVEMENT")) {
922
                SQLSelect sel = new SQLSelect();
-
 
923
                SQLTable tableEcr = getTable().getTable("ECRITURE");
927
                SQLTable tableEcr = getTable().getTable("ECRITURE");
924
                SQLTable tableMvt = getTable().getTable("MOUVEMENT");
928
                SQLTable tableMvt = getTable().getTable("MOUVEMENT");
925
                SQLTable tablePiece = getTable().getTable("PIECE");
929
                SQLTable tablePiece = getTable().getTable("PIECE");
-
 
930
                {
-
 
931
                    SQLSelect sel = new SQLSelect();
926
                sel.addSelect(tableEcr.getKey(), "COUNT");
932
                    sel.addSelect(tableEcr.getKey(), "COUNT");
927
                int idPiece = r.getForeign("ID_MOUVEMENT").getInt("ID_PIECE");
933
                    int idPiece = r.getForeign("ID_MOUVEMENT").getInt("ID_PIECE");
928
                Where w = new Where(tableMvt.getKey(), "=", tableEcr.getField("ID_MOUVEMENT"));
934
                    Where w = new Where(tableMvt.getKey(), "=", tableEcr.getField("ID_MOUVEMENT"));
929
                w = w.and(new Where(tablePiece.getKey(), "=", tableMvt.getField("ID_PIECE")));
935
                    w = w.and(new Where(tablePiece.getKey(), "=", tableMvt.getField("ID_PIECE")));
930
                w = w.and(new Where(tablePiece.getKey(), "=", idPiece));
936
                    w = w.and(new Where(tablePiece.getKey(), "=", idPiece));
Line 938... Line 944...
938
                        public void run() {
944
                            public void run() {
939
                            JOptionPane.showMessageDialog(null, "Attention cette facture est pointée ou lettrée en comptabilité. \nToute modification écrasera ces informations comptables.");
945
                                JOptionPane.showMessageDialog(null, "Attention cette facture est pointée ou lettrée en comptabilité. \nToute modification écrasera ces informations comptables.");
940
                        }
946
                            }
941
                    });
947
                        });
942
                }
948
                    }
-
 
949
                }
-
 
950
                {
-
 
951
                    SQLSelect sel = new SQLSelect();
-
 
952
                    SQLTable tableAssoc = getTable().getTable("ASSOCIATION_ANALYTIQUE");
-
 
953
                    sel.addSelect(tableAssoc.getKey(), "COUNT");
-
 
954
                    int idPiece = r.getForeign("ID_MOUVEMENT").getInt("ID_PIECE");
-
 
955
                    Where w = new Where(tableMvt.getKey(), "=", tableEcr.getField("ID_MOUVEMENT"));
-
 
956
                    w = w.and(new Where(tableAssoc.getField("ID_ECRITURE"), "=", tableEcr.getKey()));
-
 
957
                    w = w.and(new Where(tablePiece.getKey(), "=", tableMvt.getField("ID_PIECE")));
-
 
958
                    w = w.and(new Where(tablePiece.getKey(), "=", idPiece));
-
 
959
                    w = w.and(new Where(tableAssoc.getField("GESTION_AUTO"), "=", Boolean.FALSE));
-
 
960
                    sel.setWhere(w);
-
 
961
                    System.err.println(sel.asString());
-
 
962
                    Object o = Configuration.getInstance().getRoot().getBase().getDataSource().executeScalar(sel.asString());
-
 
963
                    if (o != null && ((Number) o).longValue() > 0) {
-
 
964
                        SwingUtilities.invokeLater(new Runnable() {
943
 
965
 
-
 
966
                            @Override
-
 
967
                            public void run() {
-
 
968
                                JOptionPane.showMessageDialog(null,
-
 
969
                                        "Attention la répartition analytique a été modifié manuellement sur cette facture. \nToute modification écrasera ces informations comptables.");
-
 
970
                            }
-
 
971
                        });
-
 
972
                    }
-
 
973
                }
944
            }
974
            }
945
        }
975
        }
946
            super.select(r);
976
            super.select(r);
947
 
977
 
948
        if (r != null) {
978
        if (r != null) {
Line 954... Line 984...
954
            } else {
984
            } else {
955
                setAcompte(false);
985
                setAcompte(false);
956
            }
986
            }
957
        }
987
        }
958
        if (this.comboClient != null) {
988
        if (this.comboClient != null) {
-
 
989
            if (getMode() != Mode.INSERTION) {
959
            this.comboClient.addValueListener(this.listenerModeReglDefaut);
990
                this.comboClient.addValueListener(this.listenerModeReglDefaut);
-
 
991
            }
960
            this.comboClient.addValueListener(this.changeClientListener);
992
            this.comboClient.addValueListener(this.changeClientListener);
961
        }
993
        }
962
        if (this.compteSel != null) {
994
        if (this.compteSel != null) {
963
            this.compteSel.addValueListener(this.changeCompteListener);
995
            this.compteSel.addValueListener(this.changeCompteListener);
964
        } // nomClient.addValueListener(changeClientListener);
996
        } // nomClient.addValueListener(changeClientListener);
Line 1048... Line 1080...
1048
 
1080
 
1049
 
1081
 
1050
                createDocument(rowFacture);
1082
                createDocument(rowFacture);
1051
 
1083
 
1052
                int idMvt = -1;
1084
                int idMvt = -1;
-
 
1085
                if (!this.checkPrevisionnelle.isSelected()) {
1053
                if (getMode() == Mode.MODIFICATION) {
1086
                    if (getMode() == Mode.MODIFICATION) {
1054
                    idMvt = rowFacture.getInt("ID_MOUVEMENT");
1087
                        idMvt = rowFacture.getInt("ID_MOUVEMENT");
1055
                    // on supprime tout ce qui est lié à la facture
1088
                        // on supprime tout ce qui est lié à la facture
1056
                    System.err.println("Archivage des fils");
1089
                        System.err.println("Archivage des fils");
1057
                    EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
1090
                        EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
1058
                    eltEcr.archiveMouvementProfondeur(idMvt, false);
1091
                        eltEcr.archiveMouvementProfondeur(idMvt, false);
1059
                }
1092
                    }
1060
 
1093
 
1061
                if (!this.checkPrevisionnelle.isSelected()) {
-
 
1062
                    System.err.println("Regeneration des ecritures");
1094
                    System.err.println("Regeneration des ecritures");
1063
                    if (idMvt > 1) {
1095
                    if (idMvt > 1) {
1064
                        new GenerationMvtSaisieVenteFacture(idSaisieVF, idMvt);
1096
                        new GenerationMvtSaisieVenteFacture(idSaisieVF, idMvt);
1065
                    } else {
1097
                    } else {
1066
                        new GenerationMvtSaisieVenteFacture(idSaisieVF);
1098
                        new GenerationMvtSaisieVenteFacture(idSaisieVF);
Line 1472... Line 1504...
1472
 
1504
 
1473
    public void setReferenceClientText(String text) {
1505
    public void setReferenceClientText(String text) {
1474
        this.refClient.setText(text);
1506
        this.refClient.setText(text);
1475
    }
1507
    }
1476
 
1508
 
1477
    protected String getLibelleStock(SQLRow row, SQLRow rowElt) {
1509
    protected String getLibelleStock(SQLRowAccessor row, SQLRowAccessor rowElt) {
1478
        return "Saisie vente facture N°" + row.getString("NUMERO");
1510
        return "Saisie vente facture N°" + row.getString("NUMERO");
1479
    }
1511
    }
1480
 
1512
 
1481
    /**
1513
    /**
1482
     * Mise à jour des stocks pour chaque article composant la facture
1514
     * Mise à jour des stocks pour chaque article composant la facture
Line 1485... Line 1517...
1485
     */
1517
     */
1486
    private void updateStock(int id) throws SQLException {
1518
    private void updateStock(int id) throws SQLException {
1487
 
1519
 
1488
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
1520
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
1489
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
1521
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
1490
 
-
 
1491
            MouvementStockSQLElement mvtStock = (MouvementStockSQLElement) Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
1522
            SQLRow row = getTable().getRow(id);
1492
            mvtStock.createMouvement(getTable().getRow(id), getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT"), new StockLabel() {
1523
            StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
1493
 
1524
 
1494
                @Override
1525
                @Override
1495
                public String getLabel(SQLRow rowOrigin, SQLRow rowElt) {
1526
                public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
1496
                    return getLibelleStock(rowOrigin, rowElt);
1527
                    return getLibelleStock(rowOrigin, rowElt);
1497
                }
1528
                }
-
 
1529
            }, row, row.getReferentRows(getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT")), Type.REAL_DELIVER);
-
 
1530
 
1498
            }, false);
1531
            stockUpdater.update();
1499
 
1532
 
1500
        }
1533
        }
1501
    }
1534
    }
1502
 
1535
 
1503
    @Override
1536
    @Override