OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 142 → Rev 156

/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/StockItemsTHUpdater.java
New file
0,0 → 1,60
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.sales.product.model.ProductComponent;
import org.openconcerto.erp.core.sales.product.model.ProductHelper;
import org.openconcerto.erp.core.supplychain.stock.element.StockItem.TypeStockMouvement;
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;
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.utils.SQLUtils;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.ListMap;
import org.openconcerto.utils.RTInterruptedException;
import org.openconcerto.utils.Tuple3;
import org.openconcerto.utils.cc.ITransformer;
 
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
 
import org.apache.commons.dbutils.ResultSetHandler;
 
public class StockItemsTHUpdater extends StockItemsUpdater {
 
public StockItemsTHUpdater(StockLabel label, SQLRowAccessor rowSource, List<? extends SQLRowAccessor> items, TypeStockUpdate t) {
super(label, rowSource, items, t);
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/DepotStockSQLElement.java
New file
0,0 → 1,85
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.ListMap;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JLabel;
import javax.swing.JTextField;
 
public class DepotStockSQLElement extends ComptaSQLConfElement {
 
public static int DEFAULT_ID = 2;
 
public DepotStockSQLElement() {
super("DEPOT_STOCK", "un dépôt", "dépôts");
}
 
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("NOM");
return l;
}
 
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
l.add("NOM");
return l;
}
 
@Override
public ListMap<String, String> getShowAs() {
return ListMap.singleton(null, "NOM");
}
 
/*
* (non-Javadoc)
*
* @see org.openconcerto.devis.SQLElement#getComponent()
*/
public SQLComponent createComponent() {
 
return new BaseSQLComponent(this) {
 
public void addViews() {
this.setLayout(new GridBagLayout());
final GridBagConstraints c = new DefaultGridBagConstraints();
 
// Qté Réelle
JLabel labelQteR = new JLabel(getLabelFor("NOM"));
this.add(labelQteR, c);
 
c.gridx++;
JTextField textNom = new JTextField(25);
this.add(textNom, c);
 
this.addSQLObject(textNom, "NOM");
}
};
}
 
@Override
protected String createCode() {
return createCodeOfPackage() + ".depot";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStockTable.java
New file
0,0 → 1,107
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.sales.product.ui.CurrencyWithSymbolRenderer;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.view.list.CellDynamicModifier;
import org.openconcerto.sql.view.list.RowValuesTable;
import org.openconcerto.sql.view.list.RowValuesTableModel;
import org.openconcerto.sql.view.list.RowValuesTablePanel;
import org.openconcerto.sql.view.list.SQLTableElement;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JTextField;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
 
public class EtatStockTable extends RowValuesTablePanel {
 
public EtatStockTable(final JTextField fieldTotal) {
 
init();
uiInit();
this.table.getModel().addTableModelListener(new TableModelListener() {
 
@Override
public void tableChanged(TableModelEvent e) {
BigDecimal total = BigDecimal.ZERO;
for (int i = 0; i < table.getRowValuesTableModel().getRowCount(); i++) {
total = total.add(table.getRowValuesTableModel().getRowValuesAt(i).getBigDecimal("T_PA"));
}
fieldTotal.setText(total.toString());
}
});
 
}
 
/**
*
*/
protected void init() {
 
final SQLElement e = getSQLElement();
 
final List<SQLTableElement> list = new ArrayList<>();
list.add(new SQLTableElement(e.getTable().getField("ID_ARTICLE")));
list.add(new SQLTableElement(e.getTable().getField("CODE")));
list.add(new SQLTableElement(e.getTable().getField("NOM")));
final SQLTableElement achat = new SQLTableElement(e.getTable().getField("PA")) {
@Override
protected Object getDefaultNullValue() {
return BigDecimal.ZERO;
}
};
achat.setRenderer(new CurrencyWithSymbolRenderer());
 
list.add(achat);
final SQLTableElement qte = new SQLTableElement(e.getTable().getField("QTE")) {
@Override
protected Object getDefaultNullValue() {
return BigDecimal.ZERO;
}
 
};
 
list.add(qte);
SQLTableElement totalHA = new SQLTableElement(e.getTable().getField("T_PA"));
totalHA.setRenderer(new CurrencyWithSymbolRenderer());
list.add(totalHA);
 
this.defaultRowVals = new SQLRowValues(getSQLElement().getTable());
this.model = new RowValuesTableModel(e, list, e.getTable().getField("ID_ARTICLE"), false, this.defaultRowVals);
this.table = new RowValuesTable(this.model, null);
 
// Calcul automatique du prix de vente unitaire HT
 
qte.addModificationListener(totalHA);
achat.addModificationListener(totalHA);
totalHA.setModifier(new CellDynamicModifier() {
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
return row.getBigDecimal("QTE").multiply(row.getBigDecimal("PA"));
}
});
 
}
 
public SQLElement getSQLElement() {
return Configuration.getInstance().getDirectory().getElement("ETAT_STOCK_ELEMENT");
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStockItemSQLElement.java
New file
0,0 → 1,65
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.SQLComponent;
 
import java.util.ArrayList;
import java.util.List;
 
public class EtatStockItemSQLElement extends ComptaSQLConfElement {
 
public EtatStockItemSQLElement() {
super("ETAT_STOCK_ELEMENT");
setDefaultGroup(new EtatStockGroup());
}
 
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("QTE");
return l;
}
 
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("QTE");
// l.add("PA");
return l;
}
//
// @Override
// public ListMap<String, String> getShowAs() {
// ListMap<String, String> map = new ListMap<String, String>();
// map.add("ID_ARTICLE", "CODE");
// map.add("ID_ARTICLE", "NOM");
// return map;
// }
 
/*
* (non-Javadoc)
*
* @see org.openconcerto.devis.SQLElement#getComponent()
*/
public SQLComponent createComponent() {
return null;
}
 
@Override
protected String createCode() {
return createCodeOfPackage() + ".state.items";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/StockItemsUpdater.java
58,6 → 58,7
private final TypeStockUpdate type;
private final boolean createMouvementStock;
private final SQLRowAccessor rowSource;
private boolean resetStockTH = false;
 
private boolean headless = false;
 
135,10 → 136,15
rowVals.put("QTE_TH", stockItem.getVirtualQty());
rowVals.put("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
rowVals.put("QTE_RECEPT_ATTENTE", stockItem.getReceiptQty());
rowVals.put("ID_ARTICLE", stockItem.getArticle().getID());
rowVals.put("ID_DEPOT_STOCK", stockItem.stock.getForeignID("ID_DEPOT_STOCK"));
rowVals.commit();
if (stockItem.getArticle().getForeignID("ID_DEPOT_STOCK") == stockItem.stock.getForeignID("ID_DEPOT_STOCK")) {
SQLRowValues rowValsArt = stockItem.getArticle().createEmptyUpdateRow();
rowValsArt.put("ID_STOCK", rowVals);
rowValsArt.commit();
}
}
if (!this.type.isEntry()) {
stockItem.fillCommandeFournisseur(cmd);
}
210,7 → 216,7
rowValsStock.put("QTE_RECEPT_ATTENTE", null);
rowValsStock.put("QTE_LIV_ATTENTE", null);
 
rowValsArt.put("ID_STOCK", rowValsStock);
rowVals.put("ID_STOCK", rowValsStock);
rowVals.put("ID_ARTICLE", rowValsArt);
 
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
233,11 → 239,11
List<SQLRowValues> result = fetcher.fetch();
for (SQLRowValues sqlRowValues : result) {
final StockItem item;
if (!items.containsKey(sqlRowValues.getForeignIDNumber("ID_ARTICLE"))) {
item = new StockItem(sqlRowValues.getForeign("ID_ARTICLE"));
items.put(sqlRowValues.getForeignIDNumber("ID_ARTICLE"), item);
if (!items.containsKey(sqlRowValues.getForeignIDNumber("ID_STOCK"))) {
item = new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), sqlRowValues.getForeign("ID_STOCK"));
items.put(sqlRowValues.getForeignIDNumber("ID_STOCK"), item);
} else {
item = items.get(sqlRowValues.getForeignIDNumber("ID_ARTICLE"));
item = items.get(sqlRowValues.getForeignIDNumber("ID_STOCK"));
}
final TypeStockMouvement t;
if (sqlRowValues.getBoolean("REEL")) {
277,7 → 283,7
}
}
if ((!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") == level) && !r.isForeignEmpty("ID_ARTICLE") && r.getForeign("ID_ARTICLE") != null) {
productComponents.add(ProductComponent.createFrom(r, qte));
productComponents.add(ProductComponent.createFrom(r, qte, r));
}
} else if (r.getInt("NIVEAU") < level) {
// BREAK si on sort de l'article composé
295,7 → 301,8
*/
private List<StockItem> fetch() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<StockItem> stockItems = new ArrayList<StockItem>(items.size());
Map<Number, StockItem> stockItems = new HashMap<Number, StockItem>();
 
String mvtStockTableQuoted = rowSource.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote();
 
// Liste des éléments à mettre à jour
326,7 → 333,13
for (ProductComponent productComp : boms) {
 
if (productComp.getProduct().getBoolean("GESTION_STOCK") && productComp.getQty().signum() != 0) {
StockItem stockItem = new StockItem(productComp.getProduct());
final StockItem stockItem;
if (!stockItems.containsKey(productComp.getStock().getID())) {
stockItem = new StockItem(productComp.getProduct(), productComp.getStock());
stockItems.put(productComp.getStock().getID(), stockItem);
} else {
stockItem = stockItems.get(productComp.getStock().getID());
}
double qteFinal = productComp.getQty().doubleValue();
 
// reliquat
341,20 → 354,20
}
 
stockItem.updateQty(qteFinal, this.type.getType());
stockItems.add(stockItem);
 
if (this.createMouvementStock) {
final Date time = this.rowSource.getDate("DATE").getTime();
BigDecimal prc = productComp.getPRC(time);
if (this.type.getType() == TypeStockMouvement.REEL || this.type.getType() == TypeStockMouvement.REEL_THEORIQUE || this.type.getType() == TypeStockMouvement.RETOUR) {
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
 
if (prc != null) {
mvtStockQuery += ",\"PRICE\"";
}
 
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + ",'" + this.rowSource.getTable().getName() + "',"
+ this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct()) + "',true, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted
+ ")";
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + "," + productComp.getStock().getID() + ",'"
+ this.rowSource.getTable().getName() + "'," + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct())
+ "',true, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
if (prc != null) {
mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
}
362,14 → 375,14
this.requests.add(mvtStockQuery);
}
if (this.type.getType() == TypeStockMouvement.THEORIQUE || this.type.getType() == TypeStockMouvement.REEL_THEORIQUE || this.type.getType() == TypeStockMouvement.RETOUR) {
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
if (prc != null) {
mvtStockQuery += ",\"PRICE\"";
}
 
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + ",'" + this.rowSource.getTable().getName() + "',"
+ this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct()) + "',false, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted
+ ")";
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + "," + productComp.getStock().getID() + ",'"
+ this.rowSource.getTable().getName() + "'," + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct())
+ "',false, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
if (prc != null) {
mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
}
380,6 → 393,10
}
}
 
return stockItems;
return new ArrayList<StockItem>(stockItems.values());
}
 
public void setResetStockTH(boolean resetStockTH) {
this.resetStockTH = resetStockTH;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/StockSQLElement.java
14,16 → 14,37
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.common.ui.PanelFrame;
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.ListMap;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import javax.swing.AbstractAction;
import javax.swing.JLabel;
import javax.swing.JTextField;
 
31,32 → 52,122
 
public StockSQLElement() {
super("STOCK", "un stock", "stocks");
getRowActions().addAll(new MouseSheetXmlListeListener(FicheArticleXmlSheet.class).getRowActions());
PredicateRowAction stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
 
@Override
public void actionPerformed(ActionEvent e) {
 
PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), IListe.get(e).getSelectedRows()), "Mise à jour des stocks");
FrameUtil.show(p);
 
}
}, true, false);
stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
getRowActions().add(stock);
}
 
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("QTE_REEL");
// l.add("QTE_TH");
return l;
return Arrays.asList("ID_ARTICLE", "QTE_MIN", "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK");
}
 
@Override
public Set<String> getReadOnlyFields() {
Set<String> s = new HashSet<>();
if (getTable().contains("ID_ARTICLE")) {
s.add("ID_ARTICLE");
}
s.add("QTE_TH");
s.add("QTE_REEL");
s.add("QTE_LIV_ATTENTE");
s.add("QTE_RECEPT_ATTENTE");
if (getTable().contains("ID_DEPOT_STOCK")) {
s.add("ID_DEPOT_STOCK");
}
return s;
}
 
@Override
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
l.add("QTE_REEL");
// l.add("QTE_TH");
return l;
return Arrays.asList("ID_DEPOT_STOCK", "QTE_REEL");
}
 
@Override
public boolean isPrivate() {
return true;
protected String getParentFFName() {
return "ID_ARTICLE";
}
 
@Override
public ListMap<String, String> getShowAs() {
if (getTable().contains("ID_DEPOT_STOCK")) {
return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK");
} else {
return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
}
}
 
public static SQLRowAccessor getStockFetched(SQLRowAccessor rowValsSource) {
SQLRowAccessor rowStock = null;
final int idDepot;
if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
} else {
idDepot = rowValsSource.getForeign("ID_ARTICLE").getForeignID("ID_DEPOT_STOCK");
}
SQLTable stockTable = rowValsSource.getTable().getTable("STOCK");
 
Collection<? extends SQLRowAccessor> rows = rowValsSource.getForeign("ID_ARTICLE").getReferentRows(stockTable);
for (SQLRowAccessor sqlRowAccessor : rows) {
if (sqlRowAccessor.getForeignID("ID_DEPOT_STOCK") == idDepot) {
rowStock = sqlRowAccessor;
break;
}
}
 
return rowStock;
}
 
public static SQLRowAccessor getStock(SQLRowAccessor rowValsSource) {
 
SQLRowAccessor rowStock = null;
final int idDepot;
if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
} else {
idDepot = rowValsSource.getForeign("ID_ARTICLE").getForeignID("ID_DEPOT_STOCK");
}
SQLTable stockTable = rowValsSource.getTable().getTable("STOCK");
SQLRowValues putRowValuesStock = new SQLRowValues(stockTable);
putRowValuesStock.putNulls(stockTable.getTable().getFieldsName());
 
SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(putRowValuesStock);
Where w = new Where(putRowValuesStock.getTable().getField("ID_DEPOT_STOCK"), "=", idDepot);
Where w2 = new Where(putRowValuesStock.getTable().getField("ID_ARTICLE"), "=", rowValsSource.getForeignID("ID_ARTICLE"));
Collection<SQLRowValues> rowValsResult = fetch.fetch(w.and(w2));
if (rowValsResult.isEmpty()) {
SQLRowValues rowValsStock = new SQLRowValues(stockTable);
rowValsStock.put("ID_ARTICLE", rowValsSource.getForeignID("ID_ARTICLE"));
rowValsStock.put("ID_DEPOT_STOCK", idDepot);
rowValsStock.put("QTE_TH", 0F);
rowValsStock.put("QTE_REEL", 0F);
rowValsStock.put("QTE_RECEPT_ATTENTE", 0F);
rowValsStock.put("QTE_LIV_ATTENTE", 0F);
try {
rowStock = rowValsStock.insert();
if (idDepot == DepotStockSQLElement.DEFAULT_ID) {
rowValsSource.getForeign("ID_ARTICLE").createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit();
}
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors la création du stock!", e);
}
} else if (rowValsResult.size() == 1) {
rowStock = rowValsResult.iterator().next();
} else if (rowValsResult.size() > 1) {
throw new IllegalStateException("2 lignes de stocks pour le même dépôt! Article " + rowValsSource.getForeign("ID_ARTICLE").getID() + " Depot " + idDepot);
}
return rowStock;
}
 
/*
* (non-Javadoc)
*
66,35 → 177,94
 
return new BaseSQLComponent(this) {
 
private JTextField textQteReel;
 
// , textQteTh;
 
public void addViews() {
this.setLayout(new GridBagLayout());
final GridBagConstraints c = new DefaultGridBagConstraints();
 
// Article
JLabel labelA = new JLabel(getLabelFor("ID_ARTICLE"));
c.weightx = 0;
this.add(labelA, c);
 
c.gridx++;
ElementComboBox boxA = new ElementComboBox();
this.add(boxA, c);
 
// Depot
JLabel labelD = new JLabel(getLabelFor("ID_DEPOT_STOCK"));
c.gridx++;
c.weightx = 0;
this.add(labelD, c);
 
c.gridx++;
ElementComboBox boxD = new ElementComboBox();
this.add(boxD, c);
 
// Qté Réelle
JLabel labelQteR = new JLabel(getLabelFor("QTE_REEL"));
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(labelQteR, c);
 
c.gridx++;
this.textQteReel = new JTextField(6);
this.add(this.textQteReel, c);
JTextField textQteReel = new JTextField(6);
this.add(textQteReel, c);
 
// Qté Théorique
// c.gridy++;
// c.gridx = 0;
// JLabel labelQteTh = new JLabel(getLabelFor("QTE_TH"));
// this.add(labelQteTh, c);
//
// c.gridx++;
// this.textQteTh = new JTextField(6, false);
// this.add(this.textQteTh, c);
// Qté Réelle
JLabel labelQteT = new JLabel(getLabelFor("QTE_TH"));
c.gridx++;
c.weightx = 0;
this.add(labelQteT, c);
 
this.addSQLObject(this.textQteReel, "QTE_REEL");
// this.addSQLObject(this.textQteTh, "QTE_TH");
c.gridx++;
JTextField textQteT = new JTextField(6);
this.add(textQteT, c);
 
// Qté Réelle
JLabel labelQteRe = new JLabel(getLabelFor("QTE_RECEPT_ATTENTE"));
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(labelQteRe, c);
 
c.gridx++;
JTextField textQteRe = new JTextField(6);
this.add(textQteRe, c);
 
JLabel labelQteL = new JLabel(getLabelFor("QTE_LIV_ATTENTE"));
c.gridx++;
c.weightx = 0;
this.add(labelQteL, c);
 
c.gridx++;
JTextField textQteL = new JTextField(6);
this.add(textQteL, c);
 
// Qté Min
JLabel labelQteTMin = new JLabel(getLabelFor("QTE_MIN"));
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(labelQteTMin, c);
 
c.gridx++;
JTextField textQteMin = new JTextField(6);
this.add(textQteMin, c);
 
this.addSQLObject(textQteReel, "QTE_REEL");
this.addSQLObject(textQteT, "QTE_TH");
this.addSQLObject(textQteMin, "QTE_MIN");
this.addSQLObject(textQteL, "QTE_LIV_ATTENTE");
this.addSQLObject(textQteRe, "QTE_RECEPT_ATTENTE");
this.addSQLObject(boxA, "ID_ARTICLE");
this.addSQLObject(boxD, "ID_DEPOT_STOCK");
}
};
}
 
@Override
protected String createCode() {
return "supplychain.stock";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/MouvementStockSQLElement.java
17,6 → 17,7
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable;
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
import org.openconcerto.sql.Configuration;
40,7 → 41,6
import org.openconcerto.sql.view.EditPanel.EditMode;
import org.openconcerto.sql.view.list.RowValuesTableModel;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.ListMap;
 
import java.math.BigDecimal;
58,8 → 58,16
super("MOUVEMENT_STOCK", "un mouvement de stock", "mouvements de stock");
}
 
@Override
public ListMap<String, String> getShowAs() {
ListMap<String, String> map = new ListMap<String, String>();
map.putCollection("ID_STOCK", "ID_DEPOT_STOCK");
return map;
}
 
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_STOCK");
l.add("DATE");
l.add("NOM");
l.add("ID_ARTICLE");
91,19 → 99,14
 
}
 
// public CollectionMap<SQLRow, List<SQLRowValues>> updateStock(List<Integer> ids) {
// return updateStock(ids, false);
// }
 
private final SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
 
/**
* Mise à jour des stocks ajoute la quantité si archive est à false
*
* @param id mouvement stock
* @param archive
* @throws SQLException
*/
public ListMap<SQLRow, SQLRowValues> updateStock(Collection<SQLRow> rowsMvt, boolean archive) {
public ListMap<SQLRow, SQLRowValues> updateStock(Collection<SQLRow> rowsMvt, boolean archive) throws SQLException {
// FIXME: if (SwingUtilities.isEventDispatchThread()) {
// throw new IllegalStateException("This method must be called outside of EDT");
// }
112,23 → 115,27
// Stock Th : inc/dec QTE_TH, inc/dec QTE_LIV_ATTENTE/inc/dec
// QTE_RECEPT_ATTENTE
 
final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
SQLTable tableCmdElt = Configuration.getInstance().getBase().getTable("COMMANDE_ELEMENT");
final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
final SQLTable tableCommandeElement = Configuration.getInstance().getBase().getTable("COMMANDE_ELEMENT");
final SQLElement elementStock = Configuration.getInstance().getDirectory().getElement("STOCK");
 
for (SQLRow rowMvtStock : rowsMvt) {
 
boolean retour = rowMvtStock.getString("SOURCE") == null || rowMvtStock.getString("SOURCE").startsWith("AVOIR_CLIENT");
// Mise à jour des stocks
SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement(sqlTableArticle);
SQLElement eltStock = Configuration.getInstance().getDirectory().getElement("STOCK");
 
final SQLRow rowArticle = rowMvtStock.getForeignRow("ID_ARTICLE");
 
SQLRow rowStock = rowArticle.getForeignRow(("ID_STOCK"));
SQLRow rowStock = rowMvtStock.getForeignRow(("ID_STOCK"));
if (rowStock == null || rowStock.isUndefined()) {
rowStock = rowArticle.getForeign("ID_STOCK");
}
 
if (rowMvtStock.getBoolean("REEL")) {
float qte = rowStock.getFloat("QTE_REEL");
float qteMvt = rowMvtStock.getFloat("QTE");
 
SQLRowValues rowVals = new SQLRowValues(eltStock.getTable());
SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
 
float qteNvlle;
float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
161,33 → 168,18
rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
 
try {
if (rowStock.getID() <= 1) {
SQLRow row = rowVals.insert();
SQLRowValues rowValsArt = new SQLRowValues(eltArticle.getTable());
rowValsArt.put("ID_STOCK", row.getID());
 
final int idArticle = rowArticle.getID();
if (idArticle > 1) {
rowValsArt.update(idArticle);
}
} else {
rowVals.update(rowStock.getID());
}
} catch (SQLException e) {
 
ExceptionHandler.handle("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"));
}
 
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
 
if (!archive && rowArticle.getTable().getFieldsName().contains("QTE_MIN") && gestionStockMin && rowArticle.getObject("QTE_MIN") != null && qteNvlle < rowArticle.getInt("QTE_MIN")) {
if (!archive && gestionStockMin && rowStock.getObject("QTE_MIN") != null && qteNvlle < rowStock.getFloat("QTE_MIN")) {
// final float qteShow = qteNvlle;
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCommandeElement);
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticle));
rowValsElt.put("ID_STYLE", 2);
final SQLRow unite = rowArticle.getForeign("ID_UNITE_VENTE");
final float qteElt = rowArticle.getInt("QTE_MIN") - qteNvlle;
final float qteElt = rowStock.getFloat("QTE_MIN") - qteNvlle;
if (unite.isUndefined() || unite.getBoolean("A_LA_PIECE")) {
rowValsElt.put("QTE", Math.round(qteElt));
rowValsElt.put("QTE_UNITAIRE", BigDecimal.ONE);
199,15 → 191,16
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * qteElt);
rowValsElt.put("T_PA_HT", rowValsElt.getLong("PA_HT") * qteElt);
rowValsElt.put("T_PA_TTC", rowValsElt.getLong("T_PA_HT") * (rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0));
 
map.add(rowArticle.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
 
}
} catch (SQLException e) {
throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
}
} else {
float qte = rowStock.getFloat("QTE_TH");
float qteMvt = rowMvtStock.getFloat("QTE");
 
SQLRowValues rowVals = new SQLRowValues(eltStock.getTable());
SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
 
float qteNvlle;
float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
241,23 → 234,10
rowVals.put("QTE_TH", qteNvlle);
rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
 
try {
if (rowStock.getID() <= 1) {
SQLRow row = rowVals.insert();
SQLRowValues rowValsArt = new SQLRowValues(eltArticle.getTable());
rowValsArt.put("ID_STOCK", row.getID());
 
final int idArticle = rowArticle.getID();
if (idArticle > 1) {
rowValsArt.update(idArticle);
}
} else {
rowVals.update(rowStock.getID());
}
} catch (SQLException e) {
 
ExceptionHandler.handle("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"));
throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
}
}
 
328,6 → 308,8
cmp.getRowValuesTable().getRowValuesTableModel().clearRows();
}
 
CommandeItemTable itemTable = cmp.getRowValuesTablePanel();
 
final RowValuesTableModel model = cmp.getRowValuesTable().getRowValuesTableModel();
for (SQLRowValues rowValsElt : e.getValue()) {
SQLRowValues rowValsMatch = null;
346,8 → 328,14
model.putValue(qte + rowValsElt.getInt("QTE"), index, "QTE");
} else {
model.addRow(rowValsElt);
if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) {
Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1");
if (o != null) {
model.putValue(o, model.getRowCount() - 1, "PRIX_METRIQUE_HA_1");
}
}
}
}
 
frame.pack();
FrameUtil.show(frame);
400,6 → 388,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".transaction";
return createCodeOfPackage() + ".transaction";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStockGroup.java
New file
0,0 → 1,29
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.ui.group.Group;
import org.openconcerto.ui.group.LayoutHints;
 
public class EtatStockGroup extends Group {
public EtatStockGroup() {
super("supplychain.stock.state");
addItem("DATE");
addItem("MONTANT_HA");
 
addItem("supplychain.stock.state.items", LayoutHints.DEFAULT_LIST_HINTS);
 
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/ComposedItemStockUpdater.java
14,6 → 14,7
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
23,10 → 24,13
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.request.UpdateBuilder;
import org.openconcerto.sql.utils.SQLUtils;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.Tuple2;
import org.openconcerto.utils.cc.ITransformer;
 
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
40,6 → 44,8
private final List<StockItem> itemsUpdated;
private final DBRoot root;
 
/// FIXME mettre à jour les stocks des kits à partir des feuilles
 
/**
* Met à jour les stocks des nomenclature composé par un des articles de itemsUpdated
*
59,14 → 65,22
public void update() throws SQLException {
// Liste des nomenclatures dépendantes des itemsUpdated
List<StockItem> items = getAllComposedItemToUpdate();
updateNomenclature(items);
}
 
public void updateNomenclature(List<StockItem> items) throws SQLException {
 
// Fecth des articles liés
getAllChildren(items);
 
List<StockItem> removedBadItem = new ArrayList<>();
// Mise à jour des stocks
for (StockItem stockItem : items) {
stockItem.updateQtyFromChildren();
if (!stockItem.updateQtyFromChildren()) {
removedBadItem.add(stockItem);
}
}
items.removeAll(removedBadItem);
 
SQLTable stockTable = root.getTable("STOCK");
List<String> requests = new ArrayList<String>();
73,7 → 87,7
for (StockItem stockItem : items) {
if (stockItem.isStockInit()) {
UpdateBuilder update = new UpdateBuilder(stockTable);
update.setWhere(new Where(stockTable.getKey(), "=", stockItem.getArticle().getForeign("ID_STOCK").getID()));
update.setWhere(new Where(stockTable.getKey(), "=", stockItem.stock.getID()));
update.setObject("QTE_REEL", stockItem.getRealQty());
update.setObject("QTE_TH", stockItem.getVirtualQty());
update.setObject("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
85,11 → 99,16
rowVals.put("QTE_TH", stockItem.getVirtualQty());
rowVals.put("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
rowVals.put("QTE_RECEPT_ATTENTE", stockItem.getReceiptQty());
rowVals.put("ID_ARTICLE", stockItem.getArticle().getID());
rowVals.put("ID_DEPOT_STOCK", stockItem.stock.getForeignID("ID_DEPOT_STOCK"));
rowVals.commit();
if (stockItem.getArticle().getForeignID("ID_DEPOT_STOCK") == stockItem.stock.getForeignID("ID_DEPOT_STOCK")) {
SQLRowValues rowValsArt = stockItem.getArticle().createEmptyUpdateRow();
rowValsArt.put("ID_STOCK", rowVals);
rowValsArt.commit();
}
}
}
 
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(requests.size());
for (String s : requests) {
106,15 → 125,17
*/
private void getAllChildren(List<StockItem> items) {
final SQLTable tableArticle = this.root.getTable("ARTICLE");
final int undefDepot = tableArticle.getTable("DEPOT_STOCK").getUndefinedID();
final SQLRowValues rowValsArt = new SQLRowValues(tableArticle);
rowValsArt.put(tableArticle.getKey().getName(), null);
 
SQLRowValues rowValsStock = new SQLRowValues(tableArticle.getForeignTable("ID_STOCK"));
SQLRowValues rowValsStock = new SQLRowValues(this.root.getTable("STOCK"));
rowValsStock.put("QTE_REEL", null);
rowValsStock.put("QTE_TH", null);
rowValsStock.put("QTE_RECEPT_ATTENTE", null);
rowValsStock.put("QTE_LIV_ATTENTE", null);
rowValsArt.put("ID_STOCK", rowValsStock);
rowValsStock.put("ID_DEPOT_STOCK", null);
rowValsStock.put("ID_ARTICLE", rowValsArt);
 
final SQLTable tableArticleElt = this.root.getTable("ARTICLE_ELEMENT");
SQLRowValues rowValsArtItem = new SQLRowValues(tableArticleElt);
124,12 → 145,14
rowValsArtItem.put("ID_ARTICLE_PARENT", null);
 
final List<Integer> ids = new ArrayList<Integer>();
Map<Integer, StockItem> mapItem = new HashMap<Integer, StockItem>();
Map<Tuple2<Integer, Integer>, StockItem> mapItem = new HashMap<Tuple2<Integer, Integer>, StockItem>();
for (StockItem stockItem : items) {
final int id = stockItem.getArticle().getID();
ids.add(id);
mapItem.put(id, stockItem);
if (stockItem.stock.getForeignID("ID_DEPOT_STOCK") != undefDepot) {
mapItem.put(Tuple2.create(id, stockItem.stock.getForeignID("ID_DEPOT_STOCK")), stockItem);
}
}
 
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsArtItem);
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
147,10 → 170,48
 
final SQLRowAccessor article = sqlRowValues.getForeign("ID_ARTICLE");
final SQLRowAccessor articleParent = sqlRowValues.getForeign("ID_ARTICLE_PARENT");
mapItem.get(articleParent.getID()).addItemComponent(new StockItemComponent(new StockItem(article), sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
if (article != null && !article.isUndefined()) {
final Collection<? extends SQLRowAccessor> referentStockRows = article.getReferentRows(this.root.getTable("STOCK"));
 
{
// Init Stock if no depot
if (referentStockRows.size() == 0) {
// init default stock depot
SQLRowValues rowVals = new SQLRowValues(article.getTable().getTable("STOCK"));
rowVals.put("ID_ARTICLE", article.getID());
rowVals.put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID);
try {
SQLRow rowStock = rowVals.commit();
article.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit();
 
System.err.println("NO DEPOT STOCK FOR ITEM " + articleParent.getID() + " -- PARENT " + articleParent.getID());
StockItem stockItem = mapItem.get(Tuple2.create(articleParent.getID(), DepotStockSQLElement.DEFAULT_ID));
if (stockItem != null) {
stockItem.addItemComponent(new StockItemComponent(new StockItem(article, rowStock), sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
} else {
System.err.println("Unable to find stock of item ARTICLE " + articleParent.getID() + " DEPOT " + DepotStockSQLElement.DEFAULT_ID);
}
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors de l'initialisation du stock de l'article", e);
}
}
}
 
for (SQLRowAccessor sqlRowAccessor : referentStockRows) {
StockItem stockItem = mapItem.get(Tuple2.create(articleParent.getID(), sqlRowAccessor.getForeignID("ID_DEPOT_STOCK")));
if (stockItem != null) {
stockItem.addItemComponent(new StockItemComponent(new StockItem(article, sqlRowAccessor), sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
} else if (sqlRowAccessor.getForeignID("ID_DEPOT_STOCK") == sqlRowAccessor.getTable().getForeignTable("ID_DEPOT_STOCK").getUndefinedID()) {
stockItem = mapItem.get(Tuple2.create(articleParent.getID(), DepotStockSQLElement.DEFAULT_ID));
stockItem.addItemComponent(new StockItemComponent(new StockItem(article, sqlRowAccessor), sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
} else {
System.err.println("Unable to find stock of item ARTICLE " + articleParent.getID() + " DEPOT " + sqlRowAccessor.getForeignID("ID_DEPOT_STOCK"));
}
}
}
}
}
 
/**
* @return l'ensemble des stockItems composés à mettre à jour
*/
168,6 → 229,7
for (SQLRowValues sqlRowValues : list) {
result.put(sqlRowValues.getID(), sqlRowValues);
}
// Liste des nomenclatures dépendantes des nomenclatures (kit dans kits)
while (size > 0) {
 
List<SQLRowValues> l = getComposedItemToUpdate(ids);
178,7 → 240,7
if (size > 0) {
ids.clear();
for (SQLRowValues r : l) {
ids.add(r.getID());
ids.add(r.getForeignID("ID_ARTICLE"));
}
}
}
186,7 → 248,7
List<StockItem> items = new ArrayList<StockItem>(result.size());
for (SQLRowValues rowVals : result.values()) {
 
StockItem item = new StockItem(rowVals);
StockItem item = new StockItem(rowVals.getForeign("ID_ARTICLE"), rowVals);
items.add(item);
}
return items;
203,29 → 265,30
final SQLRowValues rowValsArt = new SQLRowValues(tableArticle);
rowValsArt.put(tableArticle.getKey().getName(), null);
 
SQLRowValues rowValsStock = new SQLRowValues(tableArticle.getForeignTable("ID_STOCK"));
SQLRowValues rowValsStock = new SQLRowValues(this.root.getTable("STOCK"));
rowValsStock.put("QTE_REEL", null);
rowValsStock.put("QTE_TH", null);
rowValsStock.put("QTE_RECEPT_ATTENTE", null);
rowValsStock.put("QTE_LIV_ATTENTE", null);
rowValsArt.put("ID_STOCK", rowValsStock);
rowValsStock.put("ID_ARTICLE", rowValsArt);
rowValsStock.put("ID_DEPOT_STOCK", null);
 
final SQLTable tableArticleElt = this.root.getTable("ARTICLE_ELEMENT");
SQLRowValues rowValsArtItem = new SQLRowValues(tableArticleElt);
rowValsArtItem.put("ID_ARTICLE_PARENT", rowValsArt);
// SQLRowValues rowValsArtItem = new SQLRowValues(tableArticleElt);
// rowValsArtItem.put("ID_ARTICLE_PARENT", rowValsArt);
// rowValsArtItem.put("QTE", null);
// rowValsArtItem.put("QTE_UNITAIRE", null);
 
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsArt);
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsStock);
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
 
@Override
public SQLSelect transformChecked(SQLSelect input) {
final SQLSelectJoin joinFromField = input.getJoinFromField(tableArticleElt.getField("ID_ARTICLE_PARENT"));
SQLSelectJoin joinFromField = input.addJoin("RIGHT", tableArticleElt, new Where(tableArticleElt.getField("ID_ARTICLE_PARENT"), "=", input.getTable("STOCK").getField("ID_ARTICLE")));
Where w = new Where(joinFromField.getJoinedTable().getField("ID_ARTICLE"), ids);
joinFromField.setWhere(w);
Where w2 = new Where(joinFromField.getJoinedTable().getKey(), "is not", (Object) null);
input.setWhere(w2);
input.clearOrder();
input.setDistinct(true);
return input;
}
});
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStockFromInventoryFileCreator.java
New file
0,0 → 1,165
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.sales.product.model.PriceByQty;
import org.openconcerto.erp.importer.ArrayTableModel;
import org.openconcerto.erp.importer.DataImporter;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
import org.openconcerto.sql.model.SQLTable;
 
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
public class EtatStockFromInventoryFileCreator {
 
// Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
// List<String> codeKits = new ArrayList<String>();
// List<SQLRowValues> rowValsArtNonSync = new ArrayList<SQLRowValues>();
 
public void importArticles(File file, Date d) throws IOException, SQLException {
 
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
Map<String, SQLRowValues> articles = getArticles();
 
final DataImporter importer = new DataImporter(table) {
@Override
protected void customizeRowValuesToFetch(SQLRowValues vals) {
 
vals.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH");
}
};
importer.setSkipFirstLine(true);
 
ArrayTableModel m = importer.createModelFrom(file);
 
SQLRowValues rowValsEtatStock = new SQLRowValues(table.getTable("ETAT_STOCK"));
rowValsEtatStock.put("DATE", d);
SQLRow etatStock = rowValsEtatStock.commit();
BigDecimal total = BigDecimal.ZERO;
for (int i = 0; i < m.getRowCount(); i++) {
List<Object> o = m.getLineValuesAt(i);
String code = o.get(0).toString();
if (code.trim().length() == 0) {
break;
}
final String stringQty = o.get(3).toString();
Integer qty = stringQty.trim().length() == 0 ? 0 : Integer.valueOf(stringQty);
 
SQLRowValues match = articles.get(code);
if (match != null) {
 
SQLRowValues stockValues = new SQLRowValues(table.getTable("ETAT_STOCK_ELEMENT"));
 
final BigDecimal qtyB = new BigDecimal(qty);
stockValues.put("QTE", qtyB);
stockValues.put("NOM", match.getString("NOM"));
stockValues.put("CODE", match.getString("CODE"));
stockValues.put("ID_ARTICLE", match.getID());
final BigDecimal prc = getPRC(match, qty, d);
stockValues.put("PA", prc);
final BigDecimal totalElt = prc.multiply(qtyB);
stockValues.put("T_PA", totalElt);
stockValues.put("ID_ETAT_STOCK", etatStock.getID());
stockValues.commit();
 
total = total.add(totalElt);
 
} else {
System.err.println("Aucun article correspondant au code " + code);
}
}
etatStock.createEmptyUpdateRow().put("MONTANT_HA", total).commit();
}
 
public BigDecimal getPRC(SQLRowValues rowVals, int qty, Date d) {
if (rowVals.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
SQLTable table = rowVals.getTable().getDBRoot().getTable("ARTICLE_PRIX_REVIENT");
Collection<SQLRow> prcs = rowVals.asRow().getReferentRows(table);
 
BigDecimal result = null;
final List<PriceByQty> prices = new ArrayList<PriceByQty>();
 
for (SQLRow row : prcs) {
Calendar date = Calendar.getInstance();
date.set(Calendar.DAY_OF_MONTH, 1);
date.set(Calendar.MONTH, 1);
date.set(Calendar.YEAR, 2001);
if (row.getObject("DATE") != null) {
date = row.getDate("DATE");
}
prices.add(new PriceByQty(row.getLong("QTE"), row.getBigDecimal("PRIX"), date.getTime()));
}
 
result = PriceByQty.getPriceForQty(qty, prices, d);
if (result == null) {
// Can occur during editing
result = BigDecimal.ZERO;
}
return result;
} else {
return rowVals.getBigDecimal("PA_HT");
}
}
 
private Map<String, SQLRowValues> getArticles() throws SQLException {
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
SQLRowValues graph = new SQLRowValues(table);
graph.put("ID", null);
graph.put("CODE", null);
graph.put("SYNC_ID", null);
graph.put("NOM", null);
graph.put("PA_HT", null);
graph.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
 
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
SQLRowValues artElt = new SQLRowValues(tableArtElt);
artElt.put("ID", null);
artElt.put("QTE", null);
artElt.put("QTE_UNITAIRE", null);
artElt.put("ID_ARTICLE_PARENT", graph);
artElt.putRowValues("ID_ARTICLE").putNulls("ID", "CODE", "NOM").putRowValues("ID_STOCK").putNulls("QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
 
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
List<SQLRowValues> results = fetcher.fetch();
 
Map<String, SQLRowValues> vals = new HashMap<String, SQLRowValues>();
for (SQLRowValues sqlRowValues : results) {
 
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
// On ne prend que les articles simples
if (referentRows.size() == 0) {
final String code = sqlRowValues.getString("CODE");
vals.put(code, sqlRowValues);
 
} else {
 
}
}
return vals;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/ElementStockSQLElement.java
117,6 → 117,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".item";
return createCodeOfPackage() + ".item";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStockSQLElement.java
New file
0,0 → 1,202
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
import org.openconcerto.erp.core.sales.invoice.report.EtatStockInventaireXmlSheet;
import org.openconcerto.sql.element.GroupSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
import org.openconcerto.sql.model.SQLDataSource;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.utils.SQLUtils;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
import org.openconcerto.sql.view.list.SQLTableModelSource;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.ui.SwingThreadUtils;
import org.openconcerto.utils.ExceptionHandler;
 
import java.awt.Component;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
 
public class EtatStockSQLElement extends ComptaSQLConfElement {
 
public EtatStockSQLElement() {
super("ETAT_STOCK");
setDefaultGroup(new EtatStockGroup());
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Créer un état de stock") {
 
@Override
public void actionPerformed(ActionEvent e) {
EtatStockSnapshotCreator creator = new EtatStockSnapshotCreator(new Date(), getTable().getDBRoot());
creator.create();
}
}, true);
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
getRowActions().add(action);
}
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir les articles") {
 
@Override
public void actionPerformed(ActionEvent e) {
final SQLElement element = getDirectory().getElement("ETAT_STOCK_ELEMENT");
SQLTableModelSource source = element.createTableSource(new Where(element.getTable().getField("ID_ETAT_STOCK"), "=", IListe.get(e).getSelectedId()));
final ListeViewPanel panel = new ListeViewPanel(element, new IListe(source));
IListFrame frame = new IListFrame(panel);
FrameUtil.show(frame);
}
}, true);
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
getRowActions().add(action);
}
 
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Export pour inventaire") {
@Override
public void actionPerformed(ActionEvent e) {
EtatStockInventaireXmlSheet sheet = new EtatStockInventaireXmlSheet(IListe.get(e).getSelectedRow().asRow());
try {
sheet.createDocument();
sheet.showPrintAndExport(true, false, false, false, false);
} catch (Exception e1) {
ExceptionHandler.handle("Erreur lors de la création de l'inventaire", e1);
}
}
}, true);
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
getRowActions().add(action);
}
 
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Import Inventaire") {
@Override
public void actionPerformed(ActionEvent e) {
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
final FileDialog fd = new FileDialog(frame, "Import Inventaire", FileDialog.LOAD);
fd.setVisible(true);
if (fd.getFile() != null) {
final File f = new File(fd.getDirectory(), fd.getFile());
if (!f.exists()) {
JOptionPane.showMessageDialog(null, "Le ficher selectionné n'existe pas", "Erreur", JOptionPane.ERROR_MESSAGE);
} else if (f.isDirectory()) {
JOptionPane.showMessageDialog(null, "Le fichier selectionné n'est pas valide", "Erreur", JOptionPane.ERROR_MESSAGE);
} else {
new Thread(new Runnable() {
 
@Override
public void run() {
final InventaireFromEtatStockImporter impoter = new InventaireFromEtatStockImporter();
try {
SQLUtils.executeAtomic(getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
@Override
public Object handle(final SQLDataSource ds) throws SQLException, IOException {
 
impoter.importArticles(f, getTable().getDBRoot());
return null;
}
});
} catch (Exception e1) {
ExceptionHandler.handle("Erreur lors de l'importation", e1);
}
 
}
}).start();
}
}
}
}, true);
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
getRowActions().add(action);
}
}
 
@Override
protected List<String> getListFields() {
final List<String> l = new ArrayList<>(3);
l.add("DATE");
l.add("MONTANT_HA");
l.add("INVENTAIRE");
return l;
}
 
@Override
protected List<String> getComboFields() {
final List<String> l = new ArrayList<>(2);
l.add("DATE");
l.add("MONTANT_HA");
return l;
}
 
/*
* (non-Javadoc)
*
* @see org.openconcerto.devis.SQLElement#getComponent()
*/
public SQLComponent createComponent() {
return new GroupSQLComponent(this) {
 
@Override
public JComponent createEditor(String id) {
if (id.equals("supplychain.stock.state.items")) {
return new EtatStockTable((JTextField) getEditor("MONTANT_HA"));
} else {
return super.createEditor(id);
}
}
 
@Override
public void select(SQLRowAccessor r) {
super.select(r);
EtatStockTable table = (EtatStockTable) getEditor("supplychain.stock.state.items");
if (r != null) {
table.insertFrom("ID_ETAT_STOCK", r.getID());
}
}
 
@Override
public void update() {
super.update();
EtatStockTable table = (EtatStockTable) getEditor("supplychain.stock.state.items");
table.updateField("ID_ETAT_STOCK", getSelectedID());
}
};
}
 
@Override
protected String createCode() {
return createCodeOfPackage() + ".state";
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/InventaireFromEtatStockImporter.java
New file
0,0 → 1,384
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.erp.core.sales.product.model.ProductComponent;
import org.openconcerto.erp.core.sales.product.model.ProductHelper;
import org.openconcerto.erp.core.sales.product.model.ProductHelper.SupplierPriceField;
import org.openconcerto.erp.importer.ArrayTableModel;
import org.openconcerto.erp.importer.DataImporter;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.utils.SQLUtils;
 
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import org.apache.commons.dbutils.ResultSetHandler;
 
public class InventaireFromEtatStockImporter {
 
Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
List<String> codeKits = new ArrayList<String>();
 
public InventaireFromEtatStockImporter() {
 
}
 
public void importArticles(File file, DBRoot root) throws IOException, SQLException {
 
final SQLTable table = root.findTable("ARTICLE");
final SQLTable tableArtElt = root.findTable("ARTICLE_ELEMENT");
 
Map<String, SQLRowValues> articles = getArticles();
 
final DataImporter importer = new DataImporter(table) {
@Override
protected void customizeRowValuesToFetch(SQLRowValues vals) {
 
vals.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH", "ID_DEPOT_STOCK");
}
};
importer.setSkipFirstLine(true);
 
ArrayTableModel m = importer.createModelFrom(file);
 
Calendar c = Calendar.getInstance();
// c.set(Calendar.DAY_OF_MONTH, 1);
// c.set(Calendar.MONTH, Calendar.JANUARY);
// c.set(Calendar.HOUR_OF_DAY, 0);
Date today = c.getTime();
 
// TODO ne pas vider les stocks des kits, recalculer les stocks des kits
 
SQLRowValues rowVals = new SQLRowValues(table.getTable("ETAT_STOCK"));
rowVals.put("DATE", today);
rowVals.put("INVENTAIRE", Boolean.TRUE);
SQLRow rowEtat = rowVals.commit();
 
for (int i = 1; i < m.getRowCount(); i++) {
List<Object> o = m.getLineValuesAt(i);
if (o.size() >= 5) {
System.err.println(o);
String code = o.get(1).toString();
if (code.trim().length() > 0) {
 
final String stringQty = o.get(4).toString();
Double qty = stringQty.trim().length() == 0 ? 0 : Double.valueOf(stringQty);
final String stringQtyOld = o.get(3).toString();
float qtyOld = stringQtyOld.trim().length() == 0 ? 0 : Float.valueOf(stringQtyOld);
 
SQLRowValues match = articles.get(code);
if (match != null) {
 
SQLRowAccessor stockValues = match.getForeign("ID_STOCK");
 
final SQLTable tableMvt = table.getTable("MOUVEMENT_STOCK");
SQLRowValues rowValsMvtStockClotureFermeture = new SQLRowValues(tableMvt);
rowValsMvtStockClotureFermeture.put("QTE", -qtyOld);
rowValsMvtStockClotureFermeture.put("NOM", "Clôture stock avant inventaire");
rowValsMvtStockClotureFermeture.put("ID_ARTICLE", match.getID());
rowValsMvtStockClotureFermeture.put("DATE", today);
rowValsMvtStockClotureFermeture.put("REEL", Boolean.TRUE);
rowValsMvtStockClotureFermeture.put("ID_STOCK", stockValues.getID());
 
BigDecimal prc = getPRC(match, Math.round(qtyOld), today);
if (prc == null) {
prc = BigDecimal.ZERO;
}
if (tableMvt.contains("PRICE")) {
rowValsMvtStockClotureFermeture.put("PRICE", prc);
}
rowValsMvtStockClotureFermeture.put("CLOTURE", Boolean.TRUE);
rowValsMvtStockClotureFermeture.put("ID_ETAT_STOCK", rowEtat.getID());
rowValsMvtStockClotureFermeture.getGraph().store(StoreMode.COMMIT, false);
 
SQLRowValues rowValsItem = new SQLRowValues(table.getTable("ETAT_STOCK_ELEMENT"));
rowValsItem.put("ID_ETAT_STOCK", rowEtat.getID());
rowValsItem.put("PA", prc);
rowValsItem.put("PV", BigDecimal.ZERO);
rowValsItem.put("QTE", qtyOld);
rowValsItem.put("T_PA", prc.multiply(new BigDecimal(qtyOld)));
rowValsItem.put("T_PV", BigDecimal.ZERO);
rowValsItem.put("CODE", match.getString("CODE"));
rowValsItem.put("NOM", match.getString("NOM"));
rowValsItem.put("ID_ARTICLE", match.getID());
rowValsItem.getGraph().store(StoreMode.COMMIT, false);
 
SQLRowValues rowValsMvtStockClotureOuverture = new SQLRowValues(tableMvt);
rowValsMvtStockClotureOuverture.put("QTE", qty);
rowValsMvtStockClotureOuverture.put("NOM", "Mise en stock inventaire");
rowValsMvtStockClotureOuverture.put("ID_ETAT_STOCK", rowEtat.getID());
rowValsMvtStockClotureOuverture.put("ID_ARTICLE", match.getID());
rowValsMvtStockClotureOuverture.put("DATE", today);
rowValsMvtStockClotureOuverture.put("REEL", Boolean.TRUE);
rowValsMvtStockClotureOuverture.put("ID_STOCK", stockValues.getID());
rowValsMvtStockClotureOuverture.put("OUVERTURE", Boolean.TRUE);
if (tableMvt.contains("PRICE")) {
rowValsMvtStockClotureOuverture.put("PRICE", getPRC(match, qty.intValue(), today));
}
rowValsMvtStockClotureOuverture.getGraph().store(StoreMode.COMMIT, false);
 
if (!match.isForeignEmpty("ID_STOCK")) {
match.getForeign("ID_STOCK").createEmptyUpdateRow().put("QTE_REEL", qty).commit();
} else {
final SQLRowValues createEmptyUpdateRow = match.createEmptyUpdateRow();
createEmptyUpdateRow.putRowValues("ID_STOCK").put("QTE_REEL", qty);
createEmptyUpdateRow.getGraph().store(StoreMode.COMMIT, false);
 
}
 
} else {
System.err.println("Aucun article correspondant au code " + code);
}
}
}
}
 
/**
* Mise à jour des kits
*/
 
List<String> reqs = new ArrayList<String>();
for (String code : codeKits) {
System.err.println(code);
SQLRowValues rowValsKit = kits.get(code);
StockItem item = new StockItem(rowValsKit, rowValsKit.getForeign("ID_STOCK"));
Collection<SQLRowValues> elts = rowValsKit.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
for (SQLRowValues sqlRowValues : elts) {
if (sqlRowValues.getForeign("ID_ARTICLE") != null) {
item.addItemComponent(new StockItemComponent(new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), sqlRowValues.getForeign("ID_ARTICLE").getForeign("ID_STOCK")),
sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
}
}
item.updateQtyFromChildren();
reqs.add(item.getUpdateRequest());
}
 
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(reqs.size());
for (String s : reqs) {
handlers.add(null);
}
// FIXME FIRE TABLE CHANGED TO UPDATE ILISTE ??
SQLUtils.executeMultiple(table.getDBSystemRoot(), reqs, handlers);
 
/**
* Mise à jour des prix mini
*/
// for (SQLRowValues rowValsArt : rowValsArtNonSync) {
// SQLRow rowArt = rowValsArt.asRow();
// List<SQLRow> rowsPVMin =
// rowArt.getReferentRows(tableArtElt.getTable("ARTICLE_PRIX_MIN_VENTE"));
// List<SQLRow> rowsPA =
// rowArt.getReferentRows(tableArtElt.getTable("ARTICLE_TARIF_FOURNISSEUR"));
//
// // On récupére les derniers prix min valides
// Map<Integer, SQLRow> mapLastValidRows = new HashMap<Integer, SQLRow>();
// for (SQLRow rowPVMin : rowsPVMin) {
// final int qteMinPrice = rowPVMin.getInt("QTE");
// SQLRow rowValsLastValid = mapLastValidRows.get(qteMinPrice);
// if (rowValsLastValid == null || rowValsLastValid.getDate("DATE") == null ||
// rowValsLastValid.getDate("DATE").before(rowPVMin.getDate("DATE"))) {
// mapLastValidRows.put(qteMinPrice, rowPVMin);
// }
// }
//
// // On récupére les derniers Prix d'achat valide
// Map<Integer, SQLRow> mapLastValidAchatRows = new HashMap<Integer, SQLRow>();
// for (SQLRow rowPA : rowsPA) {
// final int qtePRC = rowPA.getInt("QTE");
// SQLRow rowValsLastValid = mapLastValidAchatRows.get(qtePRC);
// if (rowValsLastValid == null || rowValsLastValid.getDate("DATE_PRIX") == null ||
// rowValsLastValid.getDate("DATE_PRIX").before(rowPA.getDate("DATE_PRIX"))) {
// mapLastValidAchatRows.put(qtePRC, rowPA);
// }
// }
//
// // Mise à jour, si Prix < au prix min, du PRC et des prix min
// for (Integer qte : mapLastValidAchatRows.keySet()) {
// SQLRow rowVals = mapLastValidAchatRows.get(qte);
// checkMinPrice(rowVals, mapLastValidRows.get(qte));
// }
// }
 
}
 
private void checkMinPrice(SQLRow rowValsSuplierLastValid, SQLRow lastValidRow) {
boolean update = false;
final ProductHelper helper = new ProductHelper(rowValsSuplierLastValid.getTable().getDBRoot());
 
BigDecimal result = helper.getEnumPrice(rowValsSuplierLastValid, SupplierPriceField.COEF_PRIX_MINI);
if (result != null) {
final int qteSuplier = rowValsSuplierLastValid.getInt("QTE");
 
final Calendar date2 = rowValsSuplierLastValid.getDate("DATE_PRIX");
if (date2 != null) {
if (lastValidRow != null) {
final Calendar date1 = lastValidRow.getDate("DATE");
if ((date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR) && date1.get(Calendar.MONTH) == date2.get(Calendar.MONTH)
&& date1.get(Calendar.DAY_OF_MONTH) == date2.get(Calendar.DAY_OF_MONTH)) || date1.after(date2)) {
if (lastValidRow.getBigDecimal("PRIX") != null && lastValidRow.getInt("QTE") <= qteSuplier) {
try {
lastValidRow.asRowValues().put("PRIX", result).commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// purchaseMinPriceListTable.setPriceMin(result);
update = true;
}
} else {
if (date1.before(date2)) {
SQLRowValues rowValsToInsert = new SQLRowValues(lastValidRow.getTable());
rowValsToInsert.put("PRIX", result);
rowValsToInsert.put("DATE", rowValsSuplierLastValid.getObject("DATE_PRIX"));
rowValsToInsert.put("QTE", rowValsSuplierLastValid.getObject("QTE"));
rowValsToInsert.put("ID_ARTICLE", rowValsSuplierLastValid.getInt("ID_ARTICLE"));
try {
rowValsToInsert.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
 
}
 
public BigDecimal getPRC(SQLRowValues rowVals, int qty, Date d) {
// SQLTable table = rowVals.getTable().getDBRoot().getTable("ARTICLE_PRIX_REVIENT");
// Collection<SQLRow> prcs = rowVals.asRow().getReferentRows(table);
//
// BigDecimal result = null;
// final List<PriceByQty> prices = new ArrayList<PriceByQty>();
//
// for (SQLRow row : prcs) {
// Calendar date = Calendar.getInstance();
// date.set(Calendar.DAY_OF_MONTH, 1);
// date.set(Calendar.MONTH, 1);
// date.set(Calendar.YEAR, 2001);
// if (row.getObject("DATE") != null) {
// date = row.getDate("DATE");
// }
// prices.add(new PriceByQty(row.getLong("QTE"), row.getBigDecimal("PRIX"),
// date.getTime()));
// }
//
// result = PriceByQty.getPriceForQty(qty, prices, d);
// if (result == null) {
// // Can occur during editing
// result = BigDecimal.ZERO;
// }
 
ProductComponent comp = new ProductComponent(rowVals, new BigDecimal(qty), null, null);
return comp.getPRC(d);
// return result;
}
 
private Map<String, SQLRowValues> getArticles() throws SQLException {
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
SQLRowValues graph = new SQLRowValues(table);
graph.put("ID", null);
graph.put("CODE", null);
graph.put("NOM", null);
graph.put("NOM", null);
graph.putRowValues("ID_STOCK").putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
 
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
SQLRowValues artElt = new SQLRowValues(tableArtElt);
artElt.put("ID", null);
artElt.put("QTE", null);
artElt.put("QTE_UNITAIRE", null);
artElt.put("ID_ARTICLE_PARENT", graph);
artElt.putRowValues("ID_ARTICLE").putNulls("ID", "CODE", "NOM").putRowValues("ID_STOCK").putNulls("ID_DEPOT_STOCK", "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
 
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
List<SQLRowValues> results = fetcher.fetch();
 
Calendar c = Calendar.getInstance();
// c.set(Calendar.DAY_OF_MONTH, 1);
c.add(Calendar.MONTH, -2);
c.set(Calendar.DAY_OF_MONTH, 31);
Date dEndYear = c.getTime();
 
Map<String, SQLRowValues> vals = new HashMap<String, SQLRowValues>();
for (SQLRowValues sqlRowValues : results) {
final String code = sqlRowValues.getString("CODE");
vals.put(code, sqlRowValues);
 
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
if (referentRows.size() == 0) {
// if (!sqlRowValues.isForeignEmpty("ID_STOCK")) {
// SQLRowAccessor rowValsStock = sqlRowValues.getForeign("ID_STOCK");
// int qteReel = rowValsStock.getInt("QTE_REEL");
// {
// SQLRowValues rowValsMvtStockCloture = new
// SQLRowValues(table.getTable("MOUVEMENT_STOCK"));
// rowValsMvtStockCloture.put("QTE", -qteReel);
// rowValsMvtStockCloture.put("NOM", "Clôture du stock avant inventaire");
// rowValsMvtStockCloture.put("ID_ARTICLE", sqlRowValues.getID());
// rowValsMvtStockCloture.put("DATE", dEndYear);
// rowValsMvtStockCloture.put("REEL", Boolean.TRUE);
// rowValsMvtStockCloture.put("PRICE", getPRC(sqlRowValues, qteReel, dEndYear));
// rowValsMvtStockCloture.commit();
//
// rowValsStock.createEmptyUpdateRow().put("QTE_REEL", 0).commit();
// }
//
// } else {
// sqlRowValues.putRowValues("ID_STOCK").commit();
// }
} else {
boolean contains = false;
for (SQLRowValues sqlRowValues2 : referentRows) {
if (!sqlRowValues2.isForeignEmpty("ID_ARTICLE") && sqlRowValues2.getForeign("ID_ARTICLE") != null && sqlRowValues2.getForeign("ID_ARTICLE").getString("CODE") != null) {
if (codeKits.contains(sqlRowValues2.getForeign("ID_ARTICLE").getString("CODE"))) {
contains = true;
break;
}
}
}
if (!contains) {
codeKits.add(0, code);
} else {
codeKits.add(code);
}
kits.put(code, sqlRowValues);
// if (sqlRowValues.isForeignEmpty("ID_STOCK")) {
// sqlRowValues.putRowValues("ID_STOCK").commit();
// }
}
}
return vals;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStockSnapshotCreator.java
New file
0,0 → 1,174
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowListRSH;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.cc.ITransformer;
 
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class EtatStockSnapshotCreator {
 
private final Date d;
private final DBRoot root;
 
public EtatStockSnapshotCreator(Date d, DBRoot root) {
this.d = d;
this.root = root;
}
 
public void create() {
// Récupération des inventaires
SQLTable tableEtatStock = this.root.getTable("ETAT_STOCK");
SQLSelect sel = new SQLSelect();
sel.addSelectStar(tableEtatStock);
Where wEtat = new Where(tableEtatStock.getField("INVENTAIRE"), "=", Boolean.TRUE);
sel.setWhere(wEtat);
List<SQLRow> rowsEtatStock = SQLRowListRSH.execute(sel);
Map<Integer, Integer> mapEtatStock = new HashMap<Integer, Integer>();
for (SQLRow sqlRow : rowsEtatStock) {
SQLTable tableMvtStock = this.root.getTable("MOUVEMENT_STOCK");
SQLSelect selMvt = new SQLSelect();
selMvt.addSelect(tableMvtStock.getKey(), "MIN");
Where wMvt = new Where(tableMvtStock.getField("OUVERTURE"), "=", Boolean.TRUE);
wMvt = new Where(tableMvtStock.getField("ID_ETAT_STOCK"), "=", sqlRow.getID());
selMvt.setWhere(wMvt);
Integer idMvt = (Integer) tableMvtStock.getDBSystemRoot().getDataSource().executeScalar(selMvt.asString());
if (idMvt != null) {
mapEtatStock.put(sqlRow.getID(), idMvt);
}
}
 
Map<Integer, EtatStock> mapStockSnap = new HashMap<Integer, EtatStock>();
{
final SQLTable tableStock = this.root.getTable("MOUVEMENT_STOCK");
 
final SQLRowValues vals = new SQLRowValues(tableStock);
 
vals.put("QTE", null);
if (tableStock.contains("PRICE")) {
vals.put("PRICE", null);
}
vals.put("ID_ARTICLE", null);
// Calendar cal0116 = Calendar.getInstance();
// cal0116.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
// final Date dateDeb = cal0116.getTime();
 
// Récupération du dernier etat de stock
SQLSelect selEtatD = new SQLSelect();
selEtatD.addSelectStar(tableEtatStock);
Where wEtatD = new Where(tableEtatStock.getField("INVENTAIRE"), "=", Boolean.TRUE);
selEtatD.setWhere(wEtatD);
List<SQLRow> rowsEtatStockD = SQLRowListRSH.execute(selEtatD);
SQLRow rowEtatStockDeb = null;
for (SQLRow sqlRow : rowsEtatStockD) {
 
if (sqlRow.getDate("DATE").getTime().before(this.d)) {
if (rowEtatStockDeb == null || rowEtatStockDeb.getDate("DATE").before(sqlRow.getDate("DATE"))) {
rowEtatStockDeb = sqlRow;
}
}
 
}
final Date dateDeb;
final Integer idMvtStockDeb;
if (rowEtatStockDeb != null) {
dateDeb = rowEtatStockDeb.getDate("DATE").getTime();
idMvtStockDeb = mapEtatStock.get(rowEtatStockDeb.getID());
} else {
dateDeb = null;
idMvtStockDeb = null;
}
 
final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(vals);
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
 
@Override
public SQLSelect transformChecked(SQLSelect sel) {
 
Where w = (new Where(tableStock.getField("DATE"), "<=", d));
 
if (dateDeb != null) {
w = w.and(new Where(tableStock.getField("DATE"), ">=", dateDeb));
w = w.and(new Where(tableStock.getKey(), ">=", idMvtStockDeb));
w = w.and(new Where(tableStock.getField("CLOTURE"), "!=", Boolean.TRUE));
}
w = w.and(new Where(tableStock.getField("REEL"), "=", Boolean.TRUE));
 
sel.setWhere(w);
return sel;
}
});
 
List<SQLRowValues> list = fetcher.fetch();
 
BigDecimal totalHT = BigDecimal.ZERO;
for (int i = 0; i < list.size(); i++) {
SQLRowValues rowVF = list.get(i);
if (!rowVF.isForeignEmpty("ID_ARTICLE") && rowVF.getForeignID("ID_ARTICLE") > rowVF.getForeign("ID_ARTICLE").getTable().getUndefinedID()) {
final int foreignIDArt = rowVF.getForeignID("ID_ARTICLE");
if (!mapStockSnap.containsKey(foreignIDArt)) {
mapStockSnap.put(foreignIDArt, new EtatStock(rowVF.getForeign("ID_ARTICLE")));
}
EtatStock et = mapStockSnap.get(foreignIDArt);
et.setQte(et.getQte().add(new BigDecimal(rowVF.getFloat("QTE"))));
BigDecimal bigDecimal = BigDecimal.ZERO;
if (tableStock.contains("PRICE")) {
bigDecimal = rowVF.getBigDecimal("PRICE");
}
et.setPa(bigDecimal);
totalHT = totalHT.add(bigDecimal.multiply(new BigDecimal(rowVF.getFloat("QTE"), DecimalUtils.HIGH_PRECISION)));
}
}
 
SQLRowValues rowVals = new SQLRowValues(tableEtatStock);
rowVals.put("DATE", d);
rowVals.put("MONTANT_HA", totalHT);
 
for (EtatStock etatItem : mapStockSnap.values()) {
SQLRowValues rowValsItem = new SQLRowValues(tableEtatStock.getTable("ETAT_STOCK_ELEMENT"));
rowValsItem.put("ID_ETAT_STOCK", rowVals);
rowValsItem.put("PA", etatItem.getPa());
rowValsItem.put("PV", etatItem.getPv());
rowValsItem.put("QTE", etatItem.getQte());
rowValsItem.put("T_PA", etatItem.getTotalPA());
rowValsItem.put("T_PV", etatItem.getTotalPV());
rowValsItem.put("CODE", etatItem.getArticle().getString("CODE"));
rowValsItem.put("NOM", etatItem.getArticle().getString("NOM"));
rowValsItem.put("ID_ARTICLE", etatItem.getArticle().getID());
}
try {
rowVals.commit();
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors de la création de l'état", e);
}
}
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/EtatStock.java
New file
0,0 → 1,72
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
 
import org.openconcerto.sql.model.SQLRowAccessor;
 
import java.math.BigDecimal;
 
public class EtatStock {
 
private SQLRowAccessor article;
private BigDecimal pa, pv, qte;
 
public EtatStock(SQLRowAccessor article) {
this.article = article;
this.pa = BigDecimal.ZERO;
this.pv = BigDecimal.ZERO;
this.qte = BigDecimal.ZERO;
}
 
public BigDecimal getPa() {
return pa;
}
 
public BigDecimal getPv() {
return pv;
}
 
public SQLRowAccessor getArticle() {
return article;
}
 
public BigDecimal getQte() {
return qte;
}
 
public void setQte(BigDecimal qte) {
this.qte = qte;
}
 
public void setPa(BigDecimal pa) {
this.pa = pa;
}
 
public void setPv(BigDecimal pv) {
this.pv = pv;
}
 
public BigDecimal getTotalPV() {
return this.pv.multiply(qte);
}
 
public BigDecimal getTotalPA() {
return this.pa.multiply(qte);
}
 
public BigDecimal getEcart() {
return getTotalPV().subtract(getTotalPA());
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/StockItem.java
41,30 → 41,39
};
 
private double realQty, virtualQty, receiptQty, deliverQty;
public SQLRowAccessor article;
public SQLRowAccessor article, stock;
 
List<StockItemComponent> components = new ArrayList<StockItemComponent>();
 
public StockItem(SQLRowAccessor article) {
public StockItem(SQLRowAccessor article, SQLRowAccessor stock) {
this.article = article;
if (this.article.isForeignEmpty("ID_STOCK")) {
this.realQty = 0;
this.virtualQty = 0;
this.receiptQty = 0;
this.deliverQty = 0;
} else {
SQLRowAccessor row = this.article.getForeign("ID_STOCK");
this.realQty = row.getFloat("QTE_REEL");
this.virtualQty = row.getFloat("QTE_TH");
this.receiptQty = row.getFloat("QTE_RECEPT_ATTENTE");
this.deliverQty = row.getFloat("QTE_LIV_ATTENTE");
this.stock = stock;
this.realQty = stock.getFloat("QTE_REEL");
this.virtualQty = stock.getFloat("QTE_TH");
this.receiptQty = stock.getFloat("QTE_RECEPT_ATTENTE");
this.deliverQty = stock.getFloat("QTE_LIV_ATTENTE");
}
}
 
public void updateQty(double qty, TypeStockMouvement t) {
updateQty(qty, t, false);
}
 
public void setDeliverQty(double deliverQty) {
this.deliverQty = deliverQty;
}
 
public void setRealQty(double realQty) {
this.realQty = realQty;
}
 
public void setReceiptQty(double receiptQty) {
this.receiptQty = receiptQty;
}
 
public void setVirtualQty(double virtualQty) {
this.virtualQty = virtualQty;
}
 
public SQLRowAccessor getArticle() {
return article;
};
73,10 → 82,19
this.components.add(item);
};
 
public void updateQtyFromChildren() throws IllegalArgumentException {
public boolean updateQtyFromChildren() throws IllegalArgumentException {
if (components.size() == 0) {
throw new IllegalArgumentException("Impossible de calculé les quantités depuis les composants. Cet article n'est pas composé!");
if (this.article.isUndefined()) {
return false;
}
String code = "";
if (this.article != null && this.article.getFields().contains("CODE") && this.article.getString("CODE") != null) {
code = this.article.getString("CODE");
}
System.err.println("Impossible de mettre à jour le stock, l'articel n'est pas une nomenclature " + code);
return false;
 
}
StockItemComponent comp = components.get(0);
double real = comp.getItem().getRealQty() == 0 ? 0 : Math.ceil(comp.getItem().getRealQty() / (comp.getQty() * comp.getQtyUnit().doubleValue()));
double virtual = comp.getItem().getVirtualQty() == 0 ? 0 : Math.ceil(comp.getItem().getVirtualQty() / (comp.getQty() * comp.getQtyUnit().doubleValue()));
90,13 → 108,14
// La quantité du kit ne peut être négative
this.realQty = Math.max(0, real);
this.virtualQty = Math.max(0, virtual);
return true;
}
 
public void fillCommandeFournisseur(ListMap<SQLRow, SQLRowValues> cmd) {
 
// TODO Gestion Stock Min par depot
SQLPreferences prefs = new SQLPreferences(article.getTable().getDBRoot());
boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
if (article.getTable().getFieldsName().contains("QTE_MIN") && gestionStockMin && article.getObject("QTE_MIN") != null && getRealQty() < article.getInt("QTE_MIN")) {
if (gestionStockMin && stock.getObject("QTE_MIN") != null && getRealQty() < stock.getFloat("QTE_MIN")) {
// final float qteShow = qteNvlle;
SQLInjector inj = SQLInjector.getInjector(article.getTable(), article.getTable().getTable("COMMANDE_ELEMENT"));
final SQLRow asRow = article.asRow();
103,7 → 122,7
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(asRow));
rowValsElt.put("ID_STYLE", 2);
final SQLRowAccessor unite = article.getForeign("ID_UNITE_VENTE");
final double qteElt = article.getInt("QTE_MIN") - getRealQty();
final double qteElt = stock.getFloat("QTE_MIN") - getRealQty();
if (unite.isUndefined() || unite.getBoolean("A_LA_PIECE")) {
rowValsElt.put("QTE", Math.round(qteElt));
rowValsElt.put("QTE_UNITAIRE", BigDecimal.ONE);
213,7 → 232,7
}
 
public boolean isStockInit() {
return !this.article.isForeignEmpty("ID_STOCK");
return this.stock != null && !this.stock.isUndefined();
}
 
public void clearStockValues() {
224,9 → 243,9
}
 
public String getUpdateRequest() {
final SQLTable stockTable = this.article.getTable().getForeignTable("ID_STOCK");
final SQLTable stockTable = this.stock.getTable();
UpdateBuilder update = new UpdateBuilder(stockTable);
update.setWhere(new Where(stockTable.getKey(), "=", getArticle().getForeign("ID_STOCK").getID()));
update.setWhere(new Where(stockTable.getKey(), "=", this.stock.getID()));
update.setObject("QTE_REEL", getRealQty());
update.setObject("QTE_TH", getVirtualQty());
update.setObject("QTE_LIV_ATTENTE", getDeliverQty());
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/action/NouvelleSaisieMouvementStockAction.java
13,22 → 13,14
package org.openconcerto.erp.core.supplychain.stock.action;
 
import org.openconcerto.erp.action.CreateFrameAbstractAction;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.view.EditFrame;
import org.openconcerto.erp.action.CreateEditFrameAbstractAction;
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
import org.openconcerto.sql.PropsConfiguration;
 
import javax.swing.Action;
import javax.swing.JFrame;
public class NouvelleSaisieMouvementStockAction extends CreateEditFrameAbstractAction<MouvementStockSQLElement> {
 
public class NouvelleSaisieMouvementStockAction extends CreateFrameAbstractAction {
 
public NouvelleSaisieMouvementStockAction() {
super();
this.putValue(Action.NAME, "Saisie d'un mouvement de stock");
public NouvelleSaisieMouvementStockAction(final PropsConfiguration conf) {
super(conf, MouvementStockSQLElement.class);
}
 
@Override
public JFrame createFrame() {
return new EditFrame(Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK"));
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/action/ListeDesDepotsStocksAction.java
New file
0,0 → 1,34
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.action;
 
import org.openconcerto.erp.action.CreateFrameAbstractAction;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.ListeAddPanel;
 
import javax.swing.Action;
import javax.swing.JFrame;
 
public class ListeDesDepotsStocksAction extends CreateFrameAbstractAction {
 
public ListeDesDepotsStocksAction() {
super();
this.putValue(Action.NAME, "Liste des dépots de stocks");
}
 
public JFrame createFrame() {
return new IListFrame(new ListeAddPanel(Configuration.getInstance().getDirectory().getElement("DEPOT_STOCK")));
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/action/ListeDesMouvementsStockAction.java
13,13 → 13,12
package org.openconcerto.erp.core.supplychain.stock.action;
 
import org.openconcerto.erp.action.CreateFrameAbstractAction;
import org.openconcerto.erp.action.CreateIListFrameAbstractAction;
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.ListeAddPanel;
import org.openconcerto.ui.DefaultGridBagConstraints;
 
import java.awt.GridBagConstraints;
28,22 → 27,20
import java.awt.event.MouseEvent;
 
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
 
public class ListeDesMouvementsStockAction extends CreateFrameAbstractAction {
public class ListeDesMouvementsStockAction extends CreateIListFrameAbstractAction<MouvementStockSQLElement> {
 
public ListeDesMouvementsStockAction() {
super();
this.putValue(Action.NAME, "Liste des mouvements de stock");
public ListeDesMouvementsStockAction(final ComptaPropsConfiguration conf) {
super(conf, MouvementStockSQLElement.class);
}
 
public JFrame createFrame() {
@Override
protected void initFrame(IListFrame frame) {
super.initFrame(frame);
 
final SQLElement element = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
final IListFrame frame = new IListFrame(new ListeAddPanel(element));
final SQLElement element = getElem();
 
JTable table = frame.getPanel().getListe().getJTable();
 
72,6 → 69,5
c.anchor = GridBagConstraints.CENTER;
datePanel.setFilterOnDefault();
frame.getPanel().add(datePanel, c);
return frame;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/action/ListeDesStocksAction.java
New file
0,0 → 1,145
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.action;
 
import org.openconcerto.erp.action.CreateFrameAbstractAction;
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
import org.openconcerto.erp.core.common.ui.PanelFrame;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.FieldPath;
import org.openconcerto.sql.model.SQLBackgroundTableCache;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.model.graph.Path;
import org.openconcerto.sql.view.ListeAddPanel;
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.SQLTableModelColumn;
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.CollectionUtils;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.Tuple2;
import org.openconcerto.utils.cc.ITransformer;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
 
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
 
public class ListeDesStocksAction extends CreateFrameAbstractAction {
 
public ListeDesStocksAction() {
super();
this.putValue(Action.NAME, "Liste des stocks");
 
}
 
public JFrame createFrame() {
SQLElement eltStock = Configuration.getInstance().getDirectory().getElement("STOCK");
final SQLTable stockTable = eltStock.getTable();
final SQLTable depotTable = stockTable.getForeignTable("ID_DEPOT_STOCK");
 
List<SQLRow> rowsEtat = SQLBackgroundTableCache.getInstance().getCacheForTable(depotTable).getRows();
 
JTabbedPane tabs = new JTabbedPane();
 
for (final SQLRow sqlRow : rowsEtat) {
 
final SQLTableModelSourceOnline tableSource = eltStock.getTableSource(true);
 
SQLTableModelColumn colStock;
if (stockTable.getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
colStock = tableSource.getColumn(tableSource.getColumns().size() - 2);
} else {
 
colStock = new BaseSQLTableModelColumn("Valeur HT du stock", BigDecimal.class) {
 
@Override
protected Object show_(SQLRowAccessor stock) {
 
if (stock == null || stock.isUndefined()) {
return BigDecimal.ZERO;
} else {
float qte = stock.getFloat("QTE_REEL");
BigDecimal ha = stock.getForeign("ID_ARTICLE").getBigDecimal("PA_HT");
 
BigDecimal total = ha.multiply(new BigDecimal(qte), DecimalUtils.HIGH_PRECISION);
if (total.signum() == 1) {
return total;
} else {
return BigDecimal.ZERO;
}
}
}
 
@Override
public Set<FieldPath> getPaths() {
final SQLTable table = stockTable;
Path p = new Path(table);
Path p2 = new Path(table).addForeignField("ID_ARTICLE");
return CollectionUtils.createSet(new FieldPath(p2, "PA_HT"));
}
};
colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
tableSource.getColumns().add(colStock);
}
 
tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
 
@Override
public SQLSelect transformChecked(SQLSelect input) {
input.setWhere(new Where(input.getTable("STOCK").getField("ID_DEPOT_STOCK"), "=", sqlRow.getID()));
return input;
}
});
 
final IListe liste = new IListe(tableSource);
ListeAddPanel panel = new ListeAddPanel(eltStock, liste);
panel.setAddVisible(false);
panel.setDeleteVisible(false);
List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(1);
fields.add(Tuple2.create(colStock, IListTotalPanel.Type.SOMME));
 
IListTotalPanel total = new IListTotalPanel(liste, fields, null, "Total");
GridBagConstraints c2 = new DefaultGridBagConstraints();
c2.gridy = 4;
c2.anchor = GridBagConstraints.EAST;
c2.weightx = 0;
c2.fill = GridBagConstraints.NONE;
panel.add(total, c2);
tabs.add(sqlRow.getString("NOM"), panel);
}
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new DefaultGridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
panel.add(tabs, c);
return new PanelFrame(panel, "Liste des stocks");
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/action/ListeDesEtatsStocksAction.java
New file
0,0 → 1,24
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.supplychain.stock.action;
 
import org.openconcerto.erp.action.CreateIListFrameAbstractAction;
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.supplychain.stock.element.EtatStockSQLElement;
 
public class ListeDesEtatsStocksAction extends CreateIListFrameAbstractAction<EtatStockSQLElement> {
public ListeDesEtatsStocksAction(final ComptaPropsConfiguration conf) {
super(conf, EtatStockSQLElement.class);
}
}