OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 177
Line 23... Line 23...
23
import org.openconcerto.erp.core.finance.payment.element.SDDMessageSQLElement.IgnoreReason;
23
import org.openconcerto.erp.core.finance.payment.element.SDDMessageSQLElement.IgnoreReason;
24
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
24
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
25
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
25
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
26
import org.openconcerto.erp.core.sales.pos.ui.TextAreaTicketPanel;
26
import org.openconcerto.erp.core.sales.pos.ui.TextAreaTicketPanel;
27
import org.openconcerto.erp.utils.TM;
27
import org.openconcerto.erp.utils.TM;
28
import org.openconcerto.sql.Configuration;
-
 
29
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElement;
-
 
29
import org.openconcerto.sql.element.SQLElementDirectory;
30
import org.openconcerto.sql.model.FieldPath;
30
import org.openconcerto.sql.model.FieldPath;
31
import org.openconcerto.sql.model.SQLField;
31
import org.openconcerto.sql.model.SQLField;
32
import org.openconcerto.sql.model.SQLRowAccessor;
32
import org.openconcerto.sql.model.SQLRowAccessor;
33
import org.openconcerto.sql.model.SQLRowValues;
33
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.Where;
34
import org.openconcerto.sql.model.Where;
Line 77... Line 77...
77
    private ListeGestCommEltPanel listeFact;
77
    private ListeGestCommEltPanel listeFact;
78
    // private JButton buttonEnvoye, buttonRegle, buttonDupliquer;
78
    // private JButton buttonEnvoye, buttonRegle, buttonDupliquer;
79
    private JLabelBold textField = new JLabelBold("0");
79
    private JLabelBold textField = new JLabelBold("0");
80
    private JLabelBold textField2 = new JLabelBold("0");
80
    private JLabelBold textField2 = new JLabelBold("0");
81
 
81
 
82
    public ListeDesVentesPanel() {
82
    public ListeDesVentesPanel(final ComptaPropsConfiguration conf) {
83
        this.setLayout(new GridBagLayout());
83
        this.setLayout(new GridBagLayout());
84
        GridBagConstraints c = new GridBagConstraints();
84
        GridBagConstraints c = new GridBagConstraints();
85
        c.insets = new Insets(2, 2, 1, 2);
85
        c.insets = new Insets(2, 2, 1, 2);
86
        c.fill = GridBagConstraints.BOTH;
86
        c.fill = GridBagConstraints.BOTH;
87
        c.anchor = GridBagConstraints.NORTHWEST;
87
        c.anchor = GridBagConstraints.NORTHWEST;
Line 92... Line 92...
92
        c.weightx = 1;
92
        c.weightx = 1;
93
        c.weighty = 1;
93
        c.weighty = 1;
94
 
94
 
95
        JTabbedPane tabbedPane = new JTabbedPane();
95
        JTabbedPane tabbedPane = new JTabbedPane();
96
 
96
 
-
 
97
        final SQLElementDirectory dir = conf.getDirectory();
97
        final SQLElement elementVF = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
98
        final SQLElement elementVF = dir.getElement("SAISIE_VENTE_FACTURE");
98
        // tab Vente facture
99
        // tab Vente facture
99
        final SQLElement eltFacture = elementVF;
100
        final SQLElement eltFacture = elementVF;
100
        final SQLTableModelSourceOnline src = eltFacture.getTableSource(true);
101
        final SQLTableModelSourceOnline src = eltFacture.getTableSource(true);
101
        // Filter
102
        // Filter
102
        Where wPrev = new Where(eltFacture.getTable().getField("PREVISIONNELLE"), "=", Boolean.FALSE);
103
        Where wPrev = new Where(eltFacture.getTable().getField("PREVISIONNELLE"), "=", Boolean.FALSE);
Line 148... Line 149...
148
        }
149
        }
149
 
150
 
150
        src.getColumns().add(new SQLTableModelColumnPath(new FieldPath(new Path(eltFacture.getTable()).addForeignField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME), "MessageIdentification")));
151
        src.getColumns().add(new SQLTableModelColumnPath(new FieldPath(new Path(eltFacture.getTable()).addForeignField(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME), "MessageIdentification")));
151
 
152
 
152
        this.listeFact = new ListeGestCommEltPanel(eltFacture, new IListe(src), true);
153
        this.listeFact = new ListeGestCommEltPanel(eltFacture, new IListe(src), true);
153
        final SDDMessageSQLElement sepaMsgElem = eltFacture.getDirectory().getElement(SDDMessageSQLElement.class);
-
 
154
        final String aMessageLabel = sepaMsgElem.getName().getVariant(Grammar_fr.INDEFINITE_ARTICLE_SINGULAR);
-
 
155
        this.listeFact.getListe().addIListeAction(new RowAction.PredicateRowAction(new AbstractAction("Générer " + aMessageLabel, null) {
-
 
156
            @Override
-
 
157
            public void actionPerformed(ActionEvent e) {
-
 
158
                final IListe l = IListe.get(e);
-
 
159
                final List<Integer> selectedIDs = l.getSelection().getSelectedIDs();
-
 
160
                // TODO dialog with label informing of the successful creation of message for n
-
 
161
                // invoices/n2 messages too far in the future/n3 messages with collection date
-
 
162
                // changed and having a button to open the file chooser
-
 
163
                new SwingWorker<GenerationResult, Void>() {
-
 
164
                    @Override
-
 
165
                    protected GenerationResult doInBackground() throws Exception {
-
 
166
                        return sepaMsgElem.generateXML(selectedIDs);
-
 
167
                    }
-
 
168
 
154
 
169
                    @Override
-
 
170
                    protected void done() {
-
 
171
                        final GenerationResult genRes;
-
 
172
                        try {
-
 
173
                            genRes = this.get();
-
 
174
                        } catch (Exception e) {
-
 
175
                            ExceptionHandler.handle(l, "Impossible de générer " + aMessageLabel, e);
-
 
176
                            return;
-
 
177
                        }
-
 
178
                        final int includedInvoicesCount = genRes.getIncludedInvoicesCount();
-
 
179
                        final Map<String, Object> tmMap = new HashMap<>();
-
 
180
                        tmMap.put("msgElem", sepaMsgElem.getName());
-
 
181
                        tmMap.put("invoiceElem", elementVF.getName());
-
 
182
                        tmMap.put("invoiceElemCount", includedInvoicesCount);
-
 
183
                        if (genRes.getDDInvoicesWithoutMessage().isEmpty()) {
-
 
184
                            JOptionPane.showMessageDialog(l, TM.getTM().trM("sddMessage.generation.noneNeeded", tmMap));
-
 
185
                        } else if (genRes.getIgnoredInvoices().isEmpty()) {
-
 
186
                            JOptionPane.showMessageDialog(l, TM.getTM().trM("sddMessage.generation.noneIgnored", tmMap));
-
 
187
                        } else {
-
 
188
                            final int futureCount = genRes.getIgnoredInvoices().getNonNull(IgnoreReason.TOO_FAR_IN_FUTURE).size();
-
 
189
                            final int duplicateCount = genRes.getIgnoredInvoices().getNonNull(IgnoreReason.DUPLICATE_MANDATE).size();
-
 
190
                            final int missingInfoCount = genRes.getIgnoredInvoices().getNonNull(IgnoreReason.MISSING_INFO).size();
-
 
191
                            tmMap.put("futureCount", futureCount);
-
 
192
                            tmMap.put("duplicateCount", duplicateCount);
-
 
193
                            tmMap.put("missingInfoCount", missingInfoCount);
-
 
194
                            final StringBuilder msg = new StringBuilder(256);
-
 
195
                            msg.append(TM.getTM().trM("sddMessage.generation.someIgnored", tmMap));
-
 
196
                            if (futureCount > 0) {
-
 
197
                                msg.append("\n- ");
-
 
198
                                msg.append(TM.getTM().trM("sddMessage.generation.someIgnored.future", tmMap));
-
 
199
                            }
-
 
200
                            if (duplicateCount > 0) {
-
 
201
                                msg.append("\n- ");
-
 
202
                                msg.append(TM.getTM().trM("sddMessage.generation.someIgnored.duplicateMandate", tmMap));
-
 
203
                            }
-
 
204
                            if (missingInfoCount > 0) {
-
 
205
                                msg.append("\n- ");
-
 
206
                                msg.append(TM.getTM().trM("sddMessage.generation.someIgnored.missingInfo", tmMap));
-
 
207
                            }
-
 
208
                            final int messageType = duplicateCount == 0 ? JOptionPane.WARNING_MESSAGE : JOptionPane.ERROR_MESSAGE;
-
 
209
                            JOptionPane.showMessageDialog(l, msg.toString(), null, messageType);
-
 
210
                        }
-
 
211
                        if (genRes.getInsertedMessage() != null) {
-
 
212
                            sepaMsgElem.exportXML(l, Collections.singletonList(genRes.getInsertedMessage()));
-
 
213
                        }
-
 
214
                    }
-
 
215
                }.execute();
-
 
216
            }
-
 
217
        }, false, true).setPredicate(IListeEvent.getNonEmptySelectionPredicate()));
-
 
218
        // TODO remove once we have a join with {SENT, OK, DEFINITIVE_ERROR, TRANSIENT_ERROR}
-
 
219
        this.listeFact.getListe().addIListeAction(new RowAction.PredicateRowAction(new AbstractAction("Prélever à nouveau", null) {
-
 
220
            @Override
-
 
221
            public void actionPerformed(ActionEvent e) {
-
 
222
                final IListe l = IListe.get(e);
-
 
223
                if (JOptionPane.showConfirmDialog(l, "Voulez-vous vraiment prélever à nouveau les factures sélectionnées ? Cette action est définitive.", "Prélever à nouveau",
-
 
224
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION)
-
 
225
                    return;
-
 
226
                final List<Integer> selectedIDs = l.getSelection().getSelectedIDs();
-
 
227
                final UpdateBuilder upd = new UpdateBuilder(l.getSource().getPrimaryTable());
-
 
228
                upd.setObject(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME, upd.getTable().getForeignTable(SaisieVenteFactureSQLElement.MESSAGE_FIELD_NAME).getUndefinedIDNumber());
-
 
229
                upd.setObject(SaisieVenteFactureSQLElement.END2END_FIELD_NAME, "");
-
 
230
                // don't allow to debit already payed invoices
-
 
231
                upd.setWhere(new Where(upd.getTable().getKey(), selectedIDs).and(Where.isNull(upd.getTable().getField("DATE_REGLEMENT"))));
-
 
232
 
-
 
233
                upd.getTable().getDBSystemRoot().getDataSource().execute(upd.asString());
-
 
234
                for (final Integer id : selectedIDs)
-
 
235
                    upd.getTable().fireTableModified(id, upd.getFieldsNames());
-
 
236
            }
-
 
237
        }, false, true).setPredicate(IListeEvent.getNonEmptySelectionPredicate()));
-
 
238
        this.listeFact.setOpaque(false);
155
        this.listeFact.setOpaque(false);
239
        this.listeFact.getListe().setModificationAllowed(true);
156
        this.listeFact.getListe().setModificationAllowed(true);
240
        final JTable tableFact = this.listeFact.getListe().getJTable();
157
        final JTable tableFact = this.listeFact.getListe().getJTable();
241
        final SQLTableModelColumn numeroCol = src.getColumn(eltFacture.getTable().getField("NUMERO"));
158
        final SQLTableModelColumn numeroCol = src.getColumn(eltFacture.getTable().getField("NUMERO"));
242
        ((TableSorter) tableFact.getModel()).setSortingStatus(src.getColumns().indexOf(numeroCol), TableSorter.ASCENDING);
159
        ((TableSorter) tableFact.getModel()).setSortingStatus(src.getColumns().indexOf(numeroCol), TableSorter.ASCENDING);
Line 314... Line 231...
314
        this.listeFact.getListe().addIListeAction(actionEnvoye);
231
        this.listeFact.getListe().addIListeAction(actionEnvoye);
315
 
232
 
316
 
233
 
317
            {
234
            {
318
                // Tab Vente caisse
235
                // Tab Vente caisse
319
                ListeViewPanel panelTicket = new ListeViewPanel(Configuration.getInstance().getDirectory().getElement("TICKET_CAISSE")) {
236
                ListeViewPanel panelTicket = new ListeViewPanel(dir.getElement("TICKET_CAISSE")) {
320
                    @Override
237
                    @Override
321
                    protected void handleAction(JButton source, ActionEvent evt) {
238
                    protected void handleAction(JButton source, ActionEvent evt) {
322
                        if (source == this.buttonModifier) {
239
                        if (source == this.buttonModifier) {
323
                            POSConfiguration posConf = POSConfiguration.getInstance();
240
                            POSConfiguration posConf = POSConfiguration.getInstance();
324
                            try {
241
                            try {
Line 363... Line 280...
363
                tabbedPane.add("Ventes caisse", panel);
280
                tabbedPane.add("Ventes caisse", panel);
364
 
281
 
365
            }
282
            }
366
            // Tab Vente comptoir
283
            // Tab Vente comptoir
367
            {
284
            {
368
                final ListeGestCommEltPanel listeVC = new ListeGestCommEltPanel(Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_COMPTOIR"), true);
285
                final ListeGestCommEltPanel listeVC = new ListeGestCommEltPanel(dir.getElement("SAISIE_VENTE_COMPTOIR"), true);
369
                listeVC.getListe().setModificationAllowed(false);
286
                listeVC.getListe().setModificationAllowed(false);
370
                listeVC.setOpaque(false);
287
                listeVC.setOpaque(false);
371
 
288
 
372
                final JTable table = listeVC.getListe().getJTable();
289
                final JTable table = listeVC.getListe().getJTable();
373
                for (int i = 0; i < table.getColumnCount(); i++) {
290
                for (int i = 0; i < table.getColumnCount(); i++) {