OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 179 → Rev 180

/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/action/TransfertStockPanel.java
20,7 → 20,9
import org.openconcerto.erp.core.supplychain.stock.element.StockItem.TypeStockMouvement;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.model.SQLDataSource;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
81,7 → 83,6
final SQLRequestComboBox comboStockArrive = new SQLRequestComboBox();
comboStockArrive.uiInit(stockElt.createComboRequest());
 
JLabel qteReel = new JLabel("Quantité", SwingConstants.RIGHT);
final NumericTextField fieldReel = new NumericTextField();
 
fieldReel.getDocument().addDocumentListener(new SimpleDocumentListener() {
88,8 → 89,7
 
@Override
public void update(DocumentEvent e) {
buttonUpdate.setEnabled(
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null);
updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
}
});
 
97,8 → 97,7
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
buttonUpdate.setEnabled(
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null);
updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
}
});
 
106,8 → 105,7
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
buttonUpdate.setEnabled(
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null);
updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
}
});
 
115,17 → 113,16
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
buttonUpdate.setEnabled(
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null);
updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
}
});
 
GridBagConstraints c = new DefaultGridBagConstraints();
 
c.gridx = 0;
this.add(new JLabel("Intitulé"), c);
final JTextField label = new JTextField();
c.gridx++;
c.gridwidth = 2;
c.gridwidth = 1;
c.weightx = 1;
this.add(label, c);
label.setText(defaultLabel);
132,72 → 129,49
 
c.gridy++;
c.gridx = 0;
c.gridwidth = 1;
c.weightx = 0;
this.add(new JLabel("Date", SwingConstants.RIGHT), c);
final JDate date = new JDate(true);
c.gridx++;
c.weightx = 0;
this.add(date, c);
 
c.gridy++;
c.gridx = 0;
c.gridwidth = 2;
c.weightx = 0;
this.add(new JLabel("Article", SwingConstants.RIGHT), c);
c.gridx += 2;
c.gridwidth = 1;
c.weightx = 1;
c.gridx++;
this.add(comboArticle, c);
 
c.gridy++;
c.gridx = 0;
c.gridwidth = 2;
c.weightx = 0;
this.add(new JLabel("Départ", SwingConstants.RIGHT), c);
c.gridx += 2;
c.gridwidth = 1;
c.weightx = 1;
c.gridx++;
this.add(comboStockDepart, c);
 
c.gridy++;
c.gridx = 0;
c.gridwidth = 2;
c.weightx = 0;
 
this.add(new JLabel("Arrivée", SwingConstants.RIGHT), c);
c.gridx += 2;
c.gridwidth = 1;
c.weightx = 1;
c.gridx++;
this.add(comboStockArrive, c);
 
c.gridy++;
c.gridx = 0;
c.gridwidth = 2;
c.weightx = 0;
this.add(qteReel, c);
c.gridx += 2;
c.gridwidth = 1;
c.weightx = 1;
this.add(new JLabel("Quantité", SwingConstants.RIGHT), c);
c.gridx++;
this.add(fieldReel, c);
 
c.gridy++;
c.gridx = 0;
c.gridwidth = 2;
c.weightx = 0;
this.add(qteReel, c);
c.gridx += 2;
c.gridwidth = 1;
c.weightx = 1;
this.add(fieldReel, c);
 
c.gridy++;
c.gridx = 0;
JButton buttonCancel = new JButton("Annuler");
JPanel pButton = new JPanel();
pButton.add(buttonCancel);
pButton.add(buttonUpdate);
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.EAST;
c.gridwidth = 2;
c.anchor = GridBagConstraints.SOUTHEAST;
c.weightx = 0;
c.fill = GridBagConstraints.NONE;
this.add(pButton, c);
212,19 → 186,19
 
@Override
public void actionPerformed(ActionEvent e) {
 
buttonUpdate.setEnabled(false);
BigDecimal qteReel = fieldReel.getValue();
 
List<String> multipleRequestsHundred = new ArrayList<String>(100);
boolean usePrice = mvtStockTable.contains("PRICE");
List<StockItem> stockItems = new ArrayList<StockItem>();
final Date dateValue = date.getValue();
 
final SQLRow selectedRowArticle = comboArticle.getSelectedRow();
 
final SQLRow selectedRowDepotDepart = comboStockDepart.getSelectedRow();
final SQLRow selectedRowDepotArrivee = comboStockArrive.getSelectedRow();
try {
SQLUtils.executeAtomic(selectedRowDepotDepart.getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, SQLException>() {
@Override
public Object handle(SQLDataSource ds) throws SQLException {
{
// DEPART
final SQLRowAccessor rowStockDepart = ProductComponent.findOrCreateStock(selectedRowArticle, selectedRowDepotDepart);
233,12 → 207,7
SQLRowValues rowVals = new SQLRowValues(mvtStockTable.getTable("STOCK"));
rowVals.put("ID_ARTICLE", selectedRowArticle.getID());
rowVals.put("ID_DEPOT_STOCK", selectedRowDepotDepart.getID());
try {
rowVals.commit();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
selectedRowArticle.fetchValues();
item = new StockItem(selectedRowArticle, rowStockDepart);
}
245,28 → 214,22
stockItems.add(item);
double diff = -qteReel.doubleValue();
item.updateQty(diff, TypeStockMouvement.REEL);
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), true, usePrice));
 
multipleRequestsHundred
.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), true, usePrice));
item.updateQty(diff, TypeStockMouvement.THEORIQUE);
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), false, usePrice));
 
multipleRequestsHundred
.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), false, usePrice));
multipleRequestsHundred.add(item.getUpdateRequest());
}
// ARRIVEE
{
final SQLRowAccessor rowStockArrivee = ProductComponent.findOrCreateStock(selectedRowArticle, selectedRowDepotArrivee);
 
StockItem item = new StockItem(selectedRowArticle, rowStockArrivee);
if (!item.isStockInit()) {
SQLRowValues rowVals = new SQLRowValues(mvtStockTable.getTable("STOCK"));
rowVals.put("ID_ARTICLE", selectedRowArticle.getID());
rowVals.put("ID_DEPOT_STOCK", selectedRowDepotArrivee.getID());
try {
rowVals.commit();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
selectedRowArticle.fetchValues();
item = new StockItem(selectedRowArticle, rowStockArrivee);
}
273,16 → 236,14
stockItems.add(item);
double diff = qteReel.doubleValue();
item.updateQty(diff, TypeStockMouvement.REEL);
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), true, usePrice));
 
multipleRequestsHundred
.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), true, usePrice));
item.updateQty(diff, TypeStockMouvement.THEORIQUE);
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), false, usePrice));
 
multipleRequestsHundred
.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label.getText(), selectedRowDepotDepart, selectedRowDepotArrivee), false, usePrice));
multipleRequestsHundred.add(item.getUpdateRequest());
}
 
try {
 
final int size = multipleRequestsHundred.size();
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(size);
for (int i = 0; i < size; i++) {
290,28 → 251,18
}
SQLUtils.executeMultiple(instance.getRoot().getDBSystemRoot(), multipleRequestsHundred, handlers);
 
} catch (SQLException e1) {
ExceptionHandler.handle("Stock update error", e1);
}
 
final DBRoot root = mvtStockTable.getDBRoot();
if (root.contains("ARTICLE_ELEMENT")) {
// List<StockItem> stockItems = new ArrayList<StockItem>();
// for (SQLRowAccessor sqlRowAccessor2 : stocks) {
// final SQLRow asRow = sqlRowAccessor2.asRow();
// asRow.fetchValues();
// stockItems.add(new StockItem(asRow));
// }
// Mise à jour des stocks des nomenclatures
ComposedItemStockUpdater comp = new ComposedItemStockUpdater(root, stockItems);
try {
comp.update();
}
return null;
}
});
} catch (SQLException e1) {
e1.printStackTrace();
ExceptionHandler.handle("Stock update error", e1);
}
}
 
// liste.getModel().updateAll();
((JFrame) SwingUtilities.getRoot(TransfertStockPanel.this)).dispose();
}
});
318,14 → 269,12
}
 
private String getLabel(String label, SQLRowAccessor fromDepot, SQLRowAccessor toDepot) {
 
return label + " de " + fromDepot.getString("NOM") + " vers " + toDepot.getString("NOM");
 
}
 
private String getMvtRequest(Date time, BigDecimal prc, double qteFinal, StockItem item, String label, boolean reel, boolean usePrice) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"NOM\",\"REEL\",\"ORDRE\"";
String mvtStockQuery = "INSERT INTO " + this.mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"NOM\",\"REEL\",\"ORDRE\"";
 
if (usePrice && prc != null) {
mvtStockQuery += ",\"PRICE\"";
332,7 → 281,7
}
 
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + item.getArticle().getID() + "," + item.stock.getID() + ",'" + label + "'," + reel
+ ", (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
+ ", (SELECT (MAX(\"ORDRE\")+1) FROM " + this.mvtStockTableQuoted + ")";
if (usePrice && prc != null) {
mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
}
339,4 → 288,10
mvtStockQuery += ")";
return mvtStockQuery;
}
 
private void updateButtons(final JButton buttonUpdate, final SQLRequestComboBox comboArticle, final SQLRequestComboBox comboStockDepart, final SQLRequestComboBox comboStockArrive,
final NumericTextField fieldReel) {
buttonUpdate.setEnabled(fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null
&& comboStockDepart.getSelectedRow() != null && comboStockArrive.getSelectedRow().getID() != comboStockDepart.getSelectedRow().getID());
}
}