OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 93 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.humanresources.payroll.element;
14
 package org.openconcerto.erp.core.humanresources.payroll.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.generationEcritures.GenerationMvtAcompte;
17
import org.openconcerto.erp.generationEcritures.GenerationMvtAcompte;
18
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.BaseSQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.sqlobject.ElementComboBox;
23
import org.openconcerto.sql.sqlobject.ElementComboBox;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.utils.ExceptionHandler;
25
import org.openconcerto.utils.ExceptionHandler;
26
 
26
 
27
import java.awt.GridBagConstraints;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
28
import java.awt.GridBagLayout;
29
import java.sql.SQLException;
29
import java.sql.SQLException;
30
import java.util.ArrayList;
30
import java.util.ArrayList;
31
import java.util.List;
31
import java.util.List;
32
 
32
 
33
import javax.swing.JLabel;
33
import javax.swing.JLabel;
34
import javax.swing.JTextField;
34
import javax.swing.JTextField;
35
import javax.swing.SwingConstants;
35
import javax.swing.SwingConstants;
36
 
36
 
37
public class AcompteSQLElement extends ComptaSQLConfElement {
37
public class AcompteSQLElement extends ComptaSQLConfElement {
38
 
38
 
39
    public AcompteSQLElement() {
39
    public AcompteSQLElement() {
40
        super("ACOMPTE", "un acompte", "acompte");
40
        super("ACOMPTE", "un acompte", "acomptes");
41
    }
41
    }
42
 
42
 
43
    protected List<String> getListFields() {
43
    protected List<String> getListFields() {
44
        final List<String> list = new ArrayList<String>(2);
44
        final List<String> list = new ArrayList<String>(2);
45
        list.add("ID_SALARIE");
45
        list.add("ID_SALARIE");
46
        list.add("MONTANT");
46
        list.add("MONTANT");
47
        return list;
47
        return list;
48
    }
48
    }
49
 
49
 
50
    protected List<String> getComboFields() {
50
    protected List<String> getComboFields() {
51
        final List<String> list = new ArrayList<String>(2);
51
        final List<String> list = new ArrayList<String>(2);
52
        list.add("ID_SALARIE");
52
        list.add("ID_SALARIE");
53
        list.add("MONTANT");
53
        list.add("MONTANT");
54
        return list;
54
        return list;
55
    }
55
    }
56
 
56
 
57
    /*
57
    /*
58
     * (non-Javadoc)
58
     * (non-Javadoc)
59
     * 
59
     * 
60
     * @see org.openconcerto.devis.SQLElement#getComponent()
60
     * @see org.openconcerto.devis.SQLElement#getComponent()
61
     */
61
     */
62
    public SQLComponent createComponent() {
62
    public SQLComponent createComponent() {
63
        return new BaseSQLComponent(this) {
63
        return new BaseSQLComponent(this) {
64
 
64
 
65
            ElementComboBox comboSelSal;
65
            ElementComboBox comboSelSal;
66
            JTextField textMontant;
66
            JTextField textMontant;
67
 
67
 
68
            public void addViews() {
68
            public void addViews() {
69
 
69
 
70
                this.setLayout(new GridBagLayout());
70
                this.setLayout(new GridBagLayout());
71
                final GridBagConstraints c = new DefaultGridBagConstraints();
71
                final GridBagConstraints c = new DefaultGridBagConstraints();
72
 
72
 
73
                // Choix du salarié
73
                // Choix du salarié
74
                this.comboSelSal = new ElementComboBox();
74
                this.comboSelSal = new ElementComboBox();
75
                this.add(new JLabel("Salarié", SwingConstants.RIGHT), c);
75
                this.add(new JLabel("Salarié", SwingConstants.RIGHT), c);
76
                c.gridx++;
76
                c.gridx++;
77
                c.weightx = 1;
77
                c.weightx = 1;
78
                this.add(this.comboSelSal, c);
78
                this.add(this.comboSelSal, c);
79
                c.weightx = 0;
79
                c.weightx = 0;
80
 
80
 
81
                // Montant
81
                // Montant
82
                this.textMontant = new JTextField(10);
82
                this.textMontant = new JTextField(10);
83
                JLabel labelMontant = new JLabel("Montant");
83
                JLabel labelMontant = new JLabel("Montant");
84
                c.gridy++;
84
                c.gridy++;
85
                c.gridx = 0;
85
                c.gridx = 0;
86
                c.weighty = 1;
86
                c.weighty = 1;
87
                c.anchor = GridBagConstraints.NORTHEAST;
87
                c.anchor = GridBagConstraints.NORTHEAST;
88
                this.add(labelMontant, c);
88
                this.add(labelMontant, c);
89
                c.gridx++;
89
                c.gridx++;
90
                c.weightx = 1;
90
                c.weightx = 1;
91
                c.anchor = GridBagConstraints.NORTHWEST;
91
                c.anchor = GridBagConstraints.NORTHWEST;
92
                c.fill = GridBagConstraints.NONE;
92
                c.fill = GridBagConstraints.NONE;
93
                c.weightx = 0;
93
                c.weightx = 0;
94
                this.add(this.textMontant, c);
94
                this.add(this.textMontant, c);
95
 
95
 
96
                this.addRequiredSQLObject(this.comboSelSal, "ID_SALARIE");
96
                this.addRequiredSQLObject(this.comboSelSal, "ID_SALARIE");
97
                this.addRequiredSQLObject(this.textMontant, "MONTANT");
97
                this.addRequiredSQLObject(this.textMontant, "MONTANT");
98
            }
98
            }
99
 
99
 
100
            public int insert(SQLRow order) {
100
            public int insert(SQLRow order) {
101
 
101
 
102
                int id = super.insert(order);
102
                int id = super.insert(order);
103
                try {
103
                try {
104
                    SQLRow rowTmp = getTable().getRow(id);
104
                    SQLRow rowTmp = getTable().getRow(id);
105
                    new GenerationMvtAcompte(rowTmp);
105
                    new GenerationMvtAcompte(rowTmp);
106
 
106
 
107
                    SQLTable tableSal = getTable().getBase().getTable("SALARIE");
107
                    SQLTable tableSal = getTable().getBase().getTable("SALARIE");
108
                    SQLTable tableFichePaye = getTable().getBase().getTable("FICHE_PAYE");
108
                    SQLTable tableFichePaye = getTable().getBase().getTable("FICHE_PAYE");
109
 
109
 
110
                    SQLRow rowSal = tableSal.getRow(rowTmp.getInt("ID_SALARIE"));
110
                    SQLRow rowSal = tableSal.getRow(rowTmp.getInt("ID_SALARIE"));
111
                    SQLRow rowFiche = tableFichePaye.getRow(rowSal.getInt("ID_FICHE_PAYE"));
111
                    SQLRow rowFiche = tableFichePaye.getRow(rowSal.getInt("ID_FICHE_PAYE"));
112
 
112
 
113
                    SQLRowValues rowVals = new SQLRowValues(tableFichePaye);
113
                    SQLRowValues rowVals = new SQLRowValues(tableFichePaye);
114
 
114
 
115
                    float nouveauMontantAcompte = rowFiche.getFloat("ACOMPTE") + rowTmp.getFloat("MONTANT");
115
                    float nouveauMontantAcompte = rowFiche.getFloat("ACOMPTE") + rowTmp.getFloat("MONTANT");
116
 
116
 
117
                    rowVals.put("ACOMPTE", new Float(nouveauMontantAcompte));
117
                    rowVals.put("ACOMPTE", new Float(nouveauMontantAcompte));
118
 
118
 
119
                    rowVals.update(rowFiche.getID());
119
                    rowVals.update(rowFiche.getID());
120
                } catch (SQLException e) {
120
                } catch (SQLException e) {
121
                    ExceptionHandler.handle("Erreur lors de l'insertion", e);
121
                    ExceptionHandler.handle("Erreur lors de l'insertion", e);
122
                }
122
                }
123
 
123
 
124
                return id;
124
                return id;
125
            }
125
            }
126
 
126
 
127
        };
127
        };
128
    }
128
    }
129
 
129
 
130
    @Override
130
    @Override
131
    protected String createCode() {
131
    protected String createCode() {
132
        return createCodeFromPackage() + ".advance";
132
        return createCodeOfPackage() + ".advance";
133
    }
133
    }
134
}
134
}