OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 156
Line 11... Line 11...
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.ui.JNiceButton;
17
import org.openconcerto.erp.core.common.ui.JNiceButton;
17
import org.openconcerto.erp.core.humanresources.payroll.component.VariableRowTreeNode;
18
import org.openconcerto.erp.core.humanresources.payroll.component.VariableRowTreeNode;
18
import org.openconcerto.erp.core.humanresources.payroll.ui.ProfilPayeModel;
19
import org.openconcerto.erp.core.humanresources.payroll.ui.ProfilPayeModel;
-
 
20
import org.openconcerto.erp.model.FichePayeModel;
19
import org.openconcerto.erp.model.RubriquePayeTree;
21
import org.openconcerto.erp.model.RubriquePayeTree;
20
import org.openconcerto.sql.element.BaseSQLComponent;
22
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.ConfSQLElement;
23
import org.openconcerto.sql.element.ConfSQLElement;
22
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
-
 
25
import org.openconcerto.sql.model.DBRoot;
-
 
26
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
28
import org.openconcerto.sql.model.SQLRowListRSH;
-
 
29
import org.openconcerto.sql.model.SQLRowValues;
-
 
30
import org.openconcerto.sql.model.SQLSelect;
-
 
31
import org.openconcerto.sql.model.SQLTable;
-
 
32
import org.openconcerto.sql.model.Where;
-
 
33
import org.openconcerto.sql.request.UpdateBuilder;
24
import org.openconcerto.sql.view.IListFrame;
34
import org.openconcerto.sql.view.IListFrame;
-
 
35
import org.openconcerto.sql.view.list.IListe;
-
 
36
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
37
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
26
import org.openconcerto.ui.JLabelBold;
39
import org.openconcerto.ui.JLabelBold;
27
import org.openconcerto.ui.table.AlternateTableCellRenderer;
40
import org.openconcerto.ui.table.AlternateTableCellRenderer;
-
 
41
import org.openconcerto.utils.ExceptionHandler;
28
import org.openconcerto.utils.ListMap;
42
import org.openconcerto.utils.ListMap;
29
 
43
 
30
import java.awt.GridBagConstraints;
44
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
45
import java.awt.GridBagLayout;
32
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
47
import java.awt.event.ActionListener;
34
import java.awt.event.MouseAdapter;
48
import java.awt.event.MouseAdapter;
35
import java.awt.event.MouseEvent;
49
import java.awt.event.MouseEvent;
-
 
50
import java.sql.SQLException;
36
import java.util.ArrayList;
51
import java.util.ArrayList;
37
import java.util.List;
52
import java.util.List;
38
 
53
 
-
 
54
import javax.swing.AbstractAction;
39
import javax.swing.JButton;
55
import javax.swing.JButton;
40
import javax.swing.JLabel;
56
import javax.swing.JLabel;
-
 
57
import javax.swing.JOptionPane;
41
import javax.swing.JPanel;
58
import javax.swing.JPanel;
42
import javax.swing.JScrollPane;
59
import javax.swing.JScrollPane;
43
import javax.swing.JSplitPane;
60
import javax.swing.JSplitPane;
44
import javax.swing.JTable;
61
import javax.swing.JTable;
45
import javax.swing.JTextField;
62
import javax.swing.JTextField;
46
import javax.swing.SwingConstants;
63
import javax.swing.SwingConstants;
47
import javax.swing.tree.TreePath;
64
import javax.swing.tree.TreePath;
48
 
65
 
49
public class ProfilPayeSQLElement extends ConfSQLElement {
66
public class ProfilPayeSQLElement extends ComptaSQLConfElement {
50
 
67
 
51
    public ProfilPayeSQLElement() {
68
    public ProfilPayeSQLElement(final DBRoot root) {
52
        super("PROFIL_PAYE", "un profil de paye", "profils de paye");
69
        super(root.getTable("PROFIL_PAYE"), "un profil de paye", "profils de paye");
-
 
70
 
-
 
71
        PredicateRowAction action = new PredicateRowAction(new AbstractAction("Actualiser les salariés liès au profil") {
-
 
72
 
-
 
73
            @Override
-
 
74
            public void actionPerformed(ActionEvent e) {
-
 
75
 
-
 
76
                SQLRowAccessor rowSel = IListe.get(e).getSelectedRow();
-
 
77
 
-
 
78
                // Listes des rubriques du profil
-
 
79
                SQLSelect selAllIDProfilElt = new SQLSelect();
-
 
80
                SQLTable tableProfilElt = getTable().getTable("PROFIL_PAYE_ELEMENT");
-
 
81
                selAllIDProfilElt.addSelectStar(tableProfilElt);
-
 
82
                selAllIDProfilElt.setWhere(new Where(tableProfilElt.getField("ID_PROFIL_PAYE"), "=", rowSel.getID()));
-
 
83
                selAllIDProfilElt.addFieldOrder(tableProfilElt.getField("POSITION"));
-
 
84
                List<SQLRow> profilElt = SQLRowListRSH.execute(selAllIDProfilElt);
-
 
85
 
-
 
86
                SQLSelect selSal = new SQLSelect();
-
 
87
                selSal.addSelectStar(getTable().getDBRoot().findTable("SALARIE"));
-
 
88
                List<SQLRow> rowSal = SQLRowListRSH.execute(selSal);
-
 
89
 
-
 
90
                int updateSalCount = 0; 
-
 
91
                for (SQLRow sqlRow : rowSal) {
-
 
92
 
-
 
93
                    SQLRow rowFichePaye = sqlRow.getForeign("ID_FICHE_PAYE");
-
 
94
 
-
 
95
                    if (rowFichePaye.getObject("ID_PROFIL_PAYE") != null && rowFichePaye.getForeignID("ID_PROFIL_PAYE") == rowSel.getID()) {
-
 
96
                        loadFromProfil(rowFichePaye, profilElt);
-
 
97
                        updateSalCount++;
-
 
98
                    }
-
 
99
                }
-
 
100
 
-
 
101
                JOptionPane.showMessageDialog(null, updateSalCount + " mis à jour!", "Actualisation bulletin", JOptionPane.INFORMATION_MESSAGE);
-
 
102
 
-
 
103
            }
-
 
104
        }, true);
-
 
105
        action.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
106
        getRowActions().add(action);
53
    }
107
    }
54
 
108
 
55
    protected List<String> getListFields() {
109
    protected List<String> getListFields() {
56
        final List<String> l = new ArrayList<String>();
110
        final List<String> l = new ArrayList<String>();
57
        l.add("NOM");
111
        l.add("NOM");
Line 229... Line 283...
229
 
283
 
230
    @Override
284
    @Override
231
    protected String createCode() {
285
    protected String createCode() {
232
        return "humanresources.payroll.template";
286
        return "humanresources.payroll.template";
233
    }
287
    }
-
 
288
 
-
 
289
    public void loadFromProfil(SQLRow rowFichePaye, List<SQLRow> rowProfilElt) {
-
 
290
 
-
 
291
        System.err.println("Load from profil");
-
 
292
 
-
 
293
        // resetValueFiche();
-
 
294
 
-
 
295
        // Supression des anciennes rubriques du bulletin
-
 
296
        final SQLTable ficheEltTable = rowFichePaye.getTable().getTable("FICHE_PAYE_ELEMENT");
-
 
297
        UpdateBuilder archiveElt = new UpdateBuilder(ficheEltTable);
-
 
298
        archiveElt.setObject("ARCHIVE", 1);
-
 
299
        archiveElt.setWhere(new Where(ficheEltTable.getField("ID_FICHE_PAYE"), "=", rowFichePaye.getID()));
-
 
300
        getTable().getDBSystemRoot().getDataSource().execute(archiveElt.asString());
-
 
301
 
-
 
302
        // this.vectRubrique = new Vector();
-
 
303
        SQLRowValues rowValsFiche = rowFichePaye.createEmptyUpdateRow();
-
 
304
        int position = 1;
-
 
305
        for (SQLRow profilLigne : rowProfilElt) {
-
 
306
            SQLRowValues rowVals = new SQLRowValues(ficheEltTable);
-
 
307
 
-
 
308
            String source = profilLigne.getString("SOURCE");
-
 
309
            int idSource = profilLigne.getInt("IDSOURCE");
-
 
310
            rowVals.put("NOM", getTable().getTable(source).getRow(idSource).getString("NOM"));
-
 
311
            rowVals.put("SOURCE", source);
-
 
312
            rowVals.put("IDSOURCE", idSource);
-
 
313
            rowVals.put("POSITION", position);
-
 
314
            rowVals.put("ID_FICHE_PAYE", rowValsFiche);
-
 
315
            position++;
-
 
316
        }
-
 
317
        try {
-
 
318
            rowValsFiche.commit();
-
 
319
 
-
 
320
            // actualisation de la fiche
-
 
321
            FichePayeModel model = new FichePayeModel(rowValsFiche.getID());
-
 
322
            model.loadAllElements();
-
 
323
        } catch (SQLException e) {
-
 
324
            ExceptionHandler.handle("Erreur lors de la mise à jour du bulletin!", e);
-
 
325
        }
-
 
326
    }
234
}
327
}