Line 25... |
Line 25... |
25 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
25 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
26 |
import org.openconcerto.sql.model.SQLRowValues;
|
26 |
import org.openconcerto.sql.model.SQLRowValues;
|
27 |
import org.openconcerto.sql.model.SQLRowValues.ForeignCopyMode;
|
27 |
import org.openconcerto.sql.model.SQLRowValues.ForeignCopyMode;
|
28 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
28 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
29 |
import org.openconcerto.sql.model.SQLSelect;
|
29 |
import org.openconcerto.sql.model.SQLSelect;
|
- |
|
30 |
import org.openconcerto.sql.model.SQLTable;
|
30 |
import org.openconcerto.sql.model.Where;
|
31 |
import org.openconcerto.sql.model.Where;
|
31 |
import org.openconcerto.sql.view.EditFrame;
|
32 |
import org.openconcerto.sql.view.EditFrame;
|
32 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
33 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
33 |
import org.openconcerto.sql.view.list.RowValuesTable;
|
34 |
import org.openconcerto.sql.view.list.RowValuesTable;
|
34 |
import org.openconcerto.ui.FrameUtil;
|
35 |
import org.openconcerto.ui.FrameUtil;
|
Line 163... |
Line 164... |
163 |
// fetch all fields of all table to avoid 1 request by referent row
|
164 |
// fetch all fields of all table to avoid 1 request by referent row
|
164 |
final List<Number> ids = new ArrayList<Number>(sourceRows.size());
|
165 |
final List<Number> ids = new ArrayList<Number>(sourceRows.size());
|
165 |
for (SQLRowValues sqlRowValues : sourceRows) {
|
166 |
for (SQLRowValues sqlRowValues : sourceRows) {
|
166 |
ids.add(sqlRowValues.getIDNumber());
|
167 |
ids.add(sqlRowValues.getIDNumber());
|
167 |
}
|
168 |
}
|
- |
|
169 |
|
168 |
final SQLRowValues row = sourceRows.get(0).deepCopy();
|
170 |
final SQLRowValues row = new SQLRowValues(sourceRows.get(0).getTable());
|
169 |
// FIXME don't work in the general case
|
171 |
// FIXME don't work in the general case
|
170 |
for (final SQLField rk : row.getTable().getDBSystemRoot().getGraph().getReferentKeys(row.getTable())) {
|
172 |
for (final SQLField rk : row.getTable().getDBSystemRoot().getGraph().getReferentKeys(row.getTable())) {
|
171 |
final Set<SQLRowValues> referentRows = row.getReferentRows(rk);
|
173 |
final Set<SQLRowValues> referentRows = row.getReferentRows(rk);
|
172 |
if (referentRows.size() > 1) {
|
174 |
if (referentRows.size() > 1) {
|
173 |
final Iterator<SQLRowValues> iter = new ArrayList<SQLRowValues>(referentRows).iterator();
|
175 |
final Iterator<SQLRowValues> iter = new ArrayList<SQLRowValues>(referentRows).iterator();
|
Line 201... |
Line 203... |
201 |
return editFrame;
|
203 |
return editFrame;
|
202 |
} else {
|
204 |
} else {
|
203 |
throw new IllegalArgumentException("Table " + destTableName + " SQLComponent is not a TransfertBaseSQLComponent");
|
205 |
throw new IllegalArgumentException("Table " + destTableName + " SQLComponent is not a TransfertBaseSQLComponent");
|
204 |
}
|
206 |
}
|
205 |
}
|
207 |
}
|
- |
|
208 |
|
- |
|
209 |
public static boolean isAlreadyAllTransfert(final List<SQLRowValues> selectedRows, final SQLTable from, final SQLTable to, final String fieldTotalFrom, final String fieldTotalTo) {
|
- |
|
210 |
final SQLTable tableTransfert = from.getTable("TR_" + from.getName());
|
- |
|
211 |
SQLRowValues rowVals = new SQLRowValues(tableTransfert);
|
- |
|
212 |
rowVals.put("ID_" + from.getName(), new SQLRowValues(from).put("NUMERO", null).put(fieldTotalFrom, null));
|
- |
|
213 |
rowVals.putRowValues("ID_" + to.getName()).put("NUMERO", null).put(fieldTotalTo, null);
|
- |
|
214 |
rowVals.put("ID", null);
|
- |
|
215 |
|
- |
|
216 |
final List<Number> lID = new ArrayList<>();
|
- |
|
217 |
for (SQLRowValues sqlRowValues : selectedRows) {
|
- |
|
218 |
lID.add(sqlRowValues.getID());
|
- |
|
219 |
}
|
- |
|
220 |
|
- |
|
221 |
SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
|
- |
|
222 |
fetch.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
- |
|
223 |
|
- |
|
224 |
@Override
|
- |
|
225 |
public SQLSelect transformChecked(SQLSelect input) {
|
- |
|
226 |
Where w = new Where(tableTransfert.getField("ID_" + from.getName()), lID);
|
- |
|
227 |
w = w.and(new Where(tableTransfert.getField("ID_" + to.getName()), "IS NOT", (Object) null));
|
- |
|
228 |
input.setWhere(w);
|
- |
|
229 |
return input;
|
- |
|
230 |
}
|
- |
|
231 |
});
|
- |
|
232 |
|
- |
|
233 |
List<SQLRowValues> rows = fetch.fetch();
|
- |
|
234 |
if (rows != null && rows.size() > 0) {
|
- |
|
235 |
String numero = "";
|
- |
|
236 |
|
- |
|
237 |
long totalBR = 0;
|
- |
|
238 |
long totalFact = 0;
|
- |
|
239 |
Set<String> idsAdded = new HashSet<>();
|
- |
|
240 |
for (SQLRowValues sqlRow : rows) {
|
- |
|
241 |
final SQLRowAccessor foreignBR = sqlRow.getForeign("ID_" + from.getName());
|
- |
|
242 |
final SQLRowAccessor foreignFact = sqlRow.getForeign("ID_" + to.getName());
|
- |
|
243 |
numero += foreignBR.getString("NUMERO") + " ,";
|
- |
|
244 |
String fromKey = from.getName() + "-" + foreignBR.getID();
|
- |
|
245 |
if (!idsAdded.contains(fromKey)) {
|
- |
|
246 |
totalBR += foreignBR.getLong(fieldTotalFrom);
|
- |
|
247 |
idsAdded.add(fromKey);
|
- |
|
248 |
}
|
- |
|
249 |
String toKey = to.getName() + "-" + foreignFact.getID();
|
- |
|
250 |
if (!idsAdded.contains(toKey)) {
|
- |
|
251 |
totalFact += foreignFact.getLong(fieldTotalTo);
|
- |
|
252 |
idsAdded.add(toKey);
|
- |
|
253 |
}
|
- |
|
254 |
}
|
- |
|
255 |
|
- |
|
256 |
numero = numero.substring(0, numero.length() - 2);
|
- |
|
257 |
return totalBR <= totalFact;
|
- |
|
258 |
}
|
- |
|
259 |
return Boolean.FALSE;
|
- |
|
260 |
}
|
206 |
}
|
261 |
}
|