OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 180
Line 119... Line 119...
119
    public Set<String> getReadOnlyFields() {
119
    public Set<String> getReadOnlyFields() {
120
 
120
 
121
        return Collections.singleton("ID_CLIENT");
121
        return Collections.singleton("ID_CLIENT");
122
    }
122
    }
123
 
123
 
-
 
124
    @Override
-
 
125
    protected synchronized void _initTableSource(final SQLTableModelSource table) {
-
 
126
        super._initTableSource(table);
-
 
127
 
-
 
128
        final BaseSQLTableModelColumn racCol = new BaseSQLTableModelColumn("Report échéance", Boolean.class) {
-
 
129
            @Override
-
 
130
            protected Object show_(SQLRowAccessor r) {
-
 
131
 
-
 
132
                return !r.getForeign("ID_MODE_REGLEMENT").getBoolean("COMPTANT");
-
 
133
            }
-
 
134
 
-
 
135
            @Override
-
 
136
            public Set<FieldPath> getPaths() {
-
 
137
                Path p = new Path(getTable());
-
 
138
                Path p2 = p.add(p.getLast().getField("ID_MODE_REGLEMENT"));
-
 
139
                return CollectionUtils.createSet(new FieldPath(p2, "COMPTANT"));
-
 
140
            }
-
 
141
        };
-
 
142
 
-
 
143
        table.getColumns().add(racCol);
-
 
144
 
-
 
145
    }
124
 
146
 
125
    /*
147
    /*
126
     * (non-Javadoc)
148
     * (non-Javadoc)
127
     * 
149
     * 
128
     * @see org.openconcerto.devis.SQLElement#getComponent()
150
     * @see org.openconcerto.devis.SQLElement#getComponent()
Line 170... Line 192...
170
        }
192
        }
171
 
193
 
172
        super.archive(trees, cutLinks);
194
        super.archive(trees, cutLinks);
173
    }
195
    }
174
 
196
 
175
    public void regleFacture(SQLRow row) throws Exception {
197
    public void regleFacture(SQLRow rowAfter, SQLRowValues rowBefore, boolean update) throws Exception {
-
 
198
 
-
 
199
        if (update && rowBefore == null) {
-
 
200
            throw new IllegalArgumentException();
-
 
201
        } else if (update) {
-
 
202
 
-
 
203
            // Recalcul des échéances
-
 
204
            for (SQLRowAccessor rowEncaisse : rowBefore.getReferentRows(getTable().getTable("ENCAISSER_MONTANT_ELEMENT"))) {
-
 
205
 
-
 
206
                SQLRowAccessor rowEch = rowEncaisse.getForeign("ID_ECHEANCE_CLIENT");
-
 
207
                // SI une echeance est associée (paiement non comptant)
-
 
208
                if (rowEch.getID() > 1) {
-
 
209
                    SQLRowValues rowVals = rowEch.createEmptyUpdateRow();
-
 
210
                    rowVals.put("REGLE", Boolean.FALSE);
-
 
211
                    if (rowEch.getBoolean("REGLE")) {
-
 
212
                        rowVals.put("MONTANT", rowEncaisse.getLong("MONTANT_REGLE"));
-
 
213
                    } else {
-
 
214
                        rowVals.put("MONTANT", rowEch.getLong("MONTANT") + rowEncaisse.getLong("MONTANT_REGLE"));
-
 
215
                    }
-
 
216
                    rowVals.update();
-
 
217
                }
-
 
218
                // TODO si pas une echeance, echeance à creer
-
 
219
            }
-
 
220
 
-
 
221
            // On supprime les mouvements
-
 
222
            SQLSelect sel = new SQLSelect(getTable().getBase());
-
 
223
 
-
 
224
            SQLTable tableMvt = getTable().getTable("MOUVEMENT");
-
 
225
            EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(tableMvt.getTable("ECRITURE"));
-
 
226
            sel.addSelectStar(tableMvt);
-
 
227
            Where w = new Where(tableMvt.getField("SOURCE"), "=", getTable().getName());
-
 
228
            w = w.and(new Where(tableMvt.getField("IDSOURCE"), "=", rowBefore.getID()));
-
 
229
            sel.setWhere(w);
-
 
230
            List<SQLRow> list = (List<SQLRow>) getTable().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel, tableMvt));
-
 
231
            for (SQLRow sqlRow : list) {
-
 
232
                eltEcr.archiveMouvementProfondeur(sqlRow.getID(), false);
-
 
233
            }
-
 
234
 
-
 
235
            // On supprime si une prochaine échéance a été créé (ex: prélévement)
-
 
236
            final SQLRowAccessor nonEmptyForeignMvt = rowBefore.getNonEmptyForeign("ID_MOUVEMENT");
-
 
237
            if (nonEmptyForeignMvt != null && nonEmptyForeignMvt.getString("SOURCE").equals("ECHEANCE_CLIENT")) {
-
 
238
                eltEcr.archiveMouvementProfondeur(nonEmptyForeignMvt.getID(), true);
-
 
239
            }
-
 
240
        }
176
 
241
 
177
        System.out.println("Génération des ecritures du reglement");
242
        System.out.println("Génération des ecritures du reglement");
178
        String s = row.getString("NOM");
243
        String s = rowAfter.getString("NOM");
179
        SQLRow rowModeRegl = row.getForeignRow("ID_MODE_REGLEMENT");
244
        SQLRow rowModeRegl = rowAfter.getForeignRow("ID_MODE_REGLEMENT");
180
        SQLRow rowTypeRegl = rowModeRegl.getForeignRow("ID_TYPE_REGLEMENT");
245
        SQLRow rowTypeRegl = rowModeRegl.getForeignRow("ID_TYPE_REGLEMENT");
181
 
246
 
182
        // Compte Client
247
        // Compte Client
183
        SQLRow clientRow = row.getForeignRow("ID_CLIENT");
248
        SQLRow clientRow = rowAfter.getForeignRow("ID_CLIENT");
184
 
249
 
185
        String label = "Règlement vente " + ((s == null) ? "" : s) + " (" + rowTypeRegl.getString("NOM") + ") " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
250
        String label = "Règlement vente " + ((s == null) ? "" : s) + " (" + rowTypeRegl.getString("NOM") + ") " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
186
        long montant = row.getLong("MONTANT");
251
        long montant = rowAfter.getLong("MONTANT");
187
        PrixTTC ttc = new PrixTTC(montant);
252
        PrixTTC ttc = new PrixTTC(montant);
188
 
253
 
189
        List<SQLRow> l = row.getReferentRows(row.getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
254
        List<SQLRow> l = rowAfter.getReferentRows(rowAfter.getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
190
        if (l.isEmpty()) {
255
        if (l.isEmpty()) {
191
            SwingUtilities.invokeLater(new Runnable() {
256
            SwingUtilities.invokeLater(new Runnable() {
192
 
257
 
193
                @Override
258
                @Override
194
                public void run() {
259
                public void run() {
195
                    JOptionPane.showMessageDialog(null, "Un problème a été rencontré lors de l'encaissement! \n Les écritures comptables non pu être générer!");
260
                    JOptionPane.showMessageDialog(null, "Un problème a été rencontré lors de l'encaissement! \n Les écritures comptables non pu être générer!");
196
                }
261
                }
197
            });
262
            });
198
            System.err.println("Liste des échéances vides pour l'encaissement ID " + row.getID());
263
            System.err.println("Liste des échéances vides pour l'encaissement ID " + rowAfter.getID());
199
            Thread.dumpStack();
264
            Thread.dumpStack();
200
            return;
265
            return;
201
        }
266
        }
202
        new GenerationReglementVenteNG(label, clientRow, ttc, row.getDate("DATE").getTime(), rowModeRegl, row, l.get(0).getForeignRow("ID_MOUVEMENT_ECHEANCE"), false, false, row.getString("TIERS"),
267
        new GenerationReglementVenteNG(label, clientRow, ttc, rowAfter.getDate("DATE").getTime(), rowModeRegl, rowAfter, l.get(0).getForeignRow("ID_MOUVEMENT_ECHEANCE"), false, false,
203
                row.getForeign("ID_COMPTE_PCE_TIERS"));
268
                rowAfter.getString("TIERS"), rowAfter.getForeign("ID_COMPTE_PCE_TIERS"));
204
 
269
 
205
        // Mise a jour du montant de l'echeance
270
        // Mise a jour du montant de l'echeance
206
        boolean supplement = false;
271
        boolean supplement = false;
207
 
272
 
208
        if (!row.getBoolean("ACOMPTE")) {
273
        if (!rowAfter.getBoolean("ACOMPTE")) {
209
            // On marque les echeances comme reglees
274
            // On marque les echeances comme reglees
210
            for (SQLRow sqlRow : l) {
275
            for (SQLRow sqlRow : l) {
211
 
276
 
212
                final SQLRow rowEch = sqlRow.getForeignRow("ID_ECHEANCE_CLIENT");
277
                final SQLRow rowEch = sqlRow.getForeignRow("ID_ECHEANCE_CLIENT");
213
                SQLRowValues rowValsEch = rowEch.createEmptyUpdateRow();
278
                SQLRowValues rowValsEch = rowEch.createEmptyUpdateRow();