OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 151 → Rev 156

/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ModeVenteArticleSQLElement.java
72,6 → 72,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".sale";
return createCodeOfPackage() + ".sale";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/UniteVenteArticleSQLElement.java
94,6 → 94,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".unit";
return createCodeOfPackage() + ".unit";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/MetriqueSQLElement.java
80,6 → 80,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".quantity";
return createCodeOfPackage() + ".quantity";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ProductItemSQLElement.java
17,7 → 17,6
import org.openconcerto.erp.core.sales.product.component.ProductItemGroup;
import org.openconcerto.sql.element.GroupSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.utils.ListMap;
 
import java.util.ArrayList;
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/SupplierPriceListTable.java
New file
0,0 → 1,134
/*
* 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.
*/
/*
* 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.sales.product.element;
 
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
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.FieldPath;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.graph.Path;
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.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Vector;
 
public class SupplierPriceListTable extends RowValuesTablePanel {
 
public SupplierPriceListTable() {
init();
uiInit();
}
 
/**
*
*/
protected void init() {
final SQLElement eProductCost = getSQLElement();
final SQLTable productPropertyTable = eProductCost.getTable();
final List<SQLTableElement> list = new Vector<SQLTableElement>();
 
final SQLTableElement eSupplier = new SQLTableElement(productPropertyTable.getField("ID_FOURNISSEUR"));
list.add(eSupplier);
// list.add(new SQLTableElement(productPropertyTable.getField("REF_FOURNISSEUR")));
// list.add(new SQLTableElement(productPropertyTable.getField("TYPE_REAPPRO")));
// list.add(new SQLTableElement(productPropertyTable.getField("ACHETEUR")));
list.add(new SQLTableElement(productPropertyTable.getField("CODE_PAYS_ORIGINE")));
final SQLTableElement ePrixAchatDevise = new SQLTableElement(productPropertyTable.getField("PRIX_ACHAT_DEVISE_F"));
 
Path p = new Path(getSQLElement().getTable()).addForeignTable("FOURNISSEUR").addForeignField("ID_DEVISE");
ePrixAchatDevise.setRenderer(new CurrencyWithSymbolRenderer(new FieldPath(p, "CODE")));
list.add(ePrixAchatDevise);
final SQLTableElement ePrixAchat = new SQLTableElement(productPropertyTable.getField("PRIX_ACHAT"));
ePrixAchat.setRenderer(new CurrencyWithSymbolRenderer());
final CurrencyConverter c = new CurrencyConverter();
ePrixAchat.setModifier(new CellDynamicModifier() {
 
@Override
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
if (row.getObject("ID_FOURNISSEUR") == null) {
return row.getBigDecimal("PRIX_ACHAT_DEVISE_F");
}
 
final String supplierCurrency = row.getForeign("ID_FOURNISSEUR").getForeign("ID_DEVISE").getString("CODE");
final BigDecimal prixAchatDevice = row.getBigDecimal("PRIX_ACHAT_DEVISE_F");
if (prixAchatDevice == null) {
return BigDecimal.ZERO;
}
try {
BigDecimal p = c.convert(prixAchatDevice, supplierCurrency, c.getCompanyCurrencyCode(), new Date(), true);
return p.setScale(2, RoundingMode.HALF_UP);
} catch (Exception e) {
e.printStackTrace();
}
 
return BigDecimal.ZERO;
}
});
ePrixAchat.setEditable(false);
list.add(ePrixAchat);
ePrixAchatDevise.addModificationListener(ePrixAchat);
ePrixAchatDevise.addModificationListener(eSupplier);
// final SQLTableElement eConditions = new
// SQLTableElement(productPropertyTable.getField("CONDITIONS"));
// eConditions.setEditor(new JComboBoxCellEditor(new
// JComboBox(ReferenceArticleSQLElement.CONDITIONS)));
// list.add(eConditions);
list.add(new SQLTableElement(productPropertyTable.getField("QTE")));
list.add(new SQLTableElement(productPropertyTable.getField("DATE_PRIX")));
 
list.add(new SQLTableElement(productPropertyTable.getField("DELAI_REAPPRO")));
list.add(new SQLTableElement(productPropertyTable.getField("DELAI_TRANSPORT")));
// list.add(new SQLTableElement(productPropertyTable.getField("PRIORITE")));
 
this.defaultRowVals = new SQLRowValues(getSQLElement().getTable());
this.defaultRowVals.put("QTE", 1);
this.defaultRowVals.put("PRIORITE", 1);
 
this.model = new RowValuesTableModel(eProductCost, list, productPropertyTable.getField("ID_FOURNISSEUR"), false, this.defaultRowVals);
 
this.table = new RowValuesTable(this.model, null);
}
 
protected String multiply(List<String> asList) {
return null;
}
 
public SQLElement getSQLElement() {
return Configuration.getInstance().getDirectory().getElement("ARTICLE_TARIF_FOURNISSEUR");
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/FamilleEcoContributionSQLElement.java
13,9 → 13,10
package org.openconcerto.erp.core.sales.product.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.ConfSQLElement;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.ListMap;
 
27,12 → 28,17
import javax.swing.JLabel;
import javax.swing.JTextField;
 
public class FamilleEcoContributionSQLElement extends ConfSQLElement {
public class FamilleEcoContributionSQLElement extends ComptaSQLConfElement {
 
public FamilleEcoContributionSQLElement() {
super("FAMILLE_ECO_CONTRIBUTION");
public FamilleEcoContributionSQLElement(final DBRoot root) {
super(root.getTable("FAMILLE_ECO_CONTRIBUTION"));
}
 
@Override
protected String createCode() {
return this.createCodeOfPackage() + ".ewaste-family";
}
 
protected List<String> getListFields() {
final List<String> list = new ArrayList<String>(2);
list.add("NOM");
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ReferenceArticleSQLElement.java
15,11 → 15,14
 
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.common.ui.PanelFrame;
import org.openconcerto.erp.core.edm.AttachmentAction;
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.core.reports.history.ui.HistoriqueArticleFrame;
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
import org.openconcerto.erp.preferences.DefaultNXProps;
37,6 → 40,7
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.model.graph.Path;
import org.openconcerto.sql.preferences.SQLPreferences;
import org.openconcerto.sql.request.ComboSQLRequest;
import org.openconcerto.sql.view.EditFrame;
import org.openconcerto.sql.view.EditPanel.EditMode;
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
46,8 → 50,10
import org.openconcerto.sql.view.list.SQLTableModelColumn;
import org.openconcerto.sql.view.list.SQLTableModelSource;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.ui.PanelFrame;
import org.openconcerto.utils.CollectionUtils;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.ListMap;
 
import java.awt.event.ActionEvent;
55,7 → 61,9
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import javax.swing.AbstractAction;
70,7 → 78,7
public static final int AU_METRE_LARGEUR = 6;
private static final int PRIX_HA = 1;
private static final int PRIX_VT = 2;
protected final PredicateRowAction stock;
protected PredicateRowAction stock;
 
public static final String[] CONDITIONS = new String[] { "CFR", "CIF", "CPT", "DAT", "DDP", "DDU", "EXW", "FCA", "FOB" };
 
83,7 → 91,13
@Override
public void actionPerformed(ActionEvent e) {
 
PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), IListe.get(e).getSelectedRows()), "Mise à jour des stocks");
final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
List<SQLRowAccessor> l = new ArrayList<SQLRowAccessor>();
for (SQLRowValues sqlRowValues : selectedRows) {
l.add(sqlRowValues.asRow().getForeign("ID_STOCK"));
}
 
PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), l), "Mise à jour des stocks");
FrameUtil.show(p);
 
}
91,6 → 105,18
stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
getRowActions().add(stock);
 
PredicateRowAction history = new PredicateRowAction(new AbstractAction("Historique") {
 
@Override
public void actionPerformed(ActionEvent e) {
HistoriqueArticleFrame frame = new HistoriqueArticleFrame(ReferenceArticleSQLElement.this);
frame.selectId(IListe.get(e).getSelectedId());
frame.setVisible(true);
}
}, false, true);
history.setPredicate(IListeEvent.getSingleSelectionPredicate());
getRowActions().add(history);
 
PredicateRowAction clone = new PredicateRowAction(new AbstractAction("Dupliquer") {
 
@Override
112,6 → 138,7
 
PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
 
getRowActions().add(actionAttachment);
}
 
192,7 → 219,10
l.add("ID_FAMILLE_ARTICLE");
l.add("ID_FOURNISSEUR");
l.add("SKU");
 
// if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
l.add("ID_STOCK");
// }
String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
Boolean b = Boolean.valueOf(val);
if (b != null && b.booleanValue()) {
208,7 → 238,7
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
res.add(null, "CODE_BARRE");
}
res.addAll(null, "NOM", "ID_FAMILLE_ARTICLE");
res.addAll(null, "CODE", "NOM", "ID_FAMILLE_ARTICLE");
return res;
}
 
384,6 → 414,7
SQLRowValues vals = new SQLRowValues(row);
BigDecimal taux = BigDecimal.ONE.add(new BigDecimal(TaxeCache.getCache().getTauxFromId(row.getForeignID("ID_TAXE")) / 100f));
vals.put("PV_TTC", vals.getBigDecimal("PV_HT").multiply(taux));
vals.put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID);
int idArticle;
try {
 
494,8 → 525,70
&& rowVals1.getString("VALEUR_METRIQUE_2").equals(rowVals2.getString("VALEUR_METRIQUE_2")) && rowVals1.getString("VALEUR_METRIQUE_3").equals(rowVals2.getString("VALEUR_METRIQUE_3")));
}
 
public void initStock(int id) {
SQLRow row = getTable().getRow(id);
SQLSelect sel = new SQLSelect();
sel.addSelectStar(getTable().getTable("DEPOT_STOCK"));
List<SQLRow> rowsDepot = SQLRowListRSH.execute(sel);
 
SQLSelect selStock = new SQLSelect();
selStock.addSelectStar(getTable().getTable("STOCK"));
selStock.setWhere(new Where(getTable().getTable("STOCK").getField("ID_ARTICLE"), "=", id));
List<SQLRow> rowsStock = SQLRowListRSH.execute(selStock);
Map<Integer, SQLRow> initedDepot = new HashMap<>();
for (SQLRow sqlRow : rowsStock) {
initedDepot.put(sqlRow.getForeignID("ID_DEPOT_STOCK"), sqlRow);
}
 
List<StockItem> stockItems = new ArrayList<StockItem>();
for (SQLRow sqlRow : rowsDepot) {
try {
if (!initedDepot.keySet().contains(sqlRow.getID())) {
SQLRowValues rowVals = new SQLRowValues(getTable().getTable("STOCK"));
rowVals.put("ID_ARTICLE", row.getID());
rowVals.put("ID_DEPOT_STOCK", sqlRow.getID());
 
SQLRow rowStock = rowVals.commit();
if ((row.getObject("ID_DEPOT_STOCK") == null || row.isForeignEmpty("ID_DEPOT_STOCK")) && sqlRow.getID() == DepotStockSQLElement.DEFAULT_ID) {
row.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID).commit();
} else if (sqlRow.getID() == row.getForeignID("ID_DEPOT_STOCK")) {
row.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit();
}
stockItems.add(new StockItem(row, rowStock));
 
} else {
SQLRow rowExisting = initedDepot.get(sqlRow.getID());
if ((row.getObject("ID_DEPOT_STOCK") == null || row.isForeignEmpty("ID_DEPOT_STOCK")) && sqlRow.getID() == DepotStockSQLElement.DEFAULT_ID) {
row.createEmptyUpdateRow().put("ID_STOCK", rowExisting.getID()).put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID).commit();
} else if (sqlRow.getID() == row.getForeignID("ID_DEPOT_STOCK")) {
row.createEmptyUpdateRow().put("ID_STOCK", rowExisting.getID()).commit();
}
stockItems.add(new StockItem(row, rowExisting));
}
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors de l'initialisation du stock de l'article", e);
}
}
if (row.getReferentRows(getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT")).size() > 0) {
ComposedItemStockUpdater up = new ComposedItemStockUpdater(getTable().getDBRoot(), stockItems);
try {
up.updateNomenclature(stockItems);
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors de l'actualisation du stock!", e);
}
}
}
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".ref";
return createCodeOfPackage() + ".ref";
}
 
@Override
protected void _initComboRequest(ComboSQLRequest req) {
super._initComboRequest(req);
req.addToGraphToFetch("ID_DEPOT_STOCK");
// req.addForeignToGraphToFetch("ID_DEPOT_STOCK", Arrays.asList("ID"));
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ArticleCatComptableSQLElement.java
New file
0,0 → 1,92
/*
* 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.sales.product.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JLabel;
import javax.swing.SwingConstants;
 
public class ArticleCatComptableSQLElement extends ComptaSQLConfElement {
 
public ArticleCatComptableSQLElement() {
super("ARTICLE_CATEGORIE_COMPTABLE", "une liaison article catégorie comptable", "liaisons article catégorie comptable");
}
 
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("ID_CATEGORIE_COMPTABLE");
l.add("ID_COMPTE_PCE_VENTE");
l.add("ID_COMPTE_PCE_ACHAT");
l.add("ID_TAXE");
return l;
}
 
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("ID_CATEGORIE_COMPTABLE");
return l;
}
 
@Override
protected String getParentFFName() {
return "ID_ARTICLE";
}
 
/*
* (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();
 
// Famille père
final JLabel labelLangue = new JLabel(getLabelFor("ID_ARTICLE"), SwingConstants.RIGHT);
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(labelLangue, c);
 
final ElementComboBox artBox = new ElementComboBox(true, 25);
DefaultGridBagConstraints.lockMinimumSize(artBox);
c.gridx++;
c.weightx = 1;
this.add(artBox, c);
 
this.addSQLObject(artBox, "ID_ARTICLE");
}
 
};
}
 
@Override
protected String createCode() {
return createCodeOfPackage() + ".compta";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/EcoContributionSQLElement.java
13,11 → 13,11
package org.openconcerto.erp.core.sales.product.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.ConfSQLElement;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.ListMap;
 
29,12 → 29,17
import javax.swing.JLabel;
import javax.swing.JTextField;
 
public class EcoContributionSQLElement extends ConfSQLElement {
public class EcoContributionSQLElement extends ComptaSQLConfElement {
 
public EcoContributionSQLElement() {
super("ECO_CONTRIBUTION");
public EcoContributionSQLElement(final DBRoot root) {
super(root.getTable("ECO_CONTRIBUTION"));
}
 
@Override
protected String createCode() {
return this.createCodeOfPackage() + ".ewaste-tax";
}
 
protected List<String> getListFields() {
final List<String> list = new ArrayList<String>(2);
list.add("ID_FAMILLE_ECO_CONTRIBUTION");
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/CoutRevientSQLElement.java
New file
0,0 → 1,104
/*
* 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.sales.product.element;
 
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
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 CoutRevientSQLElement extends ComptaSQLConfElement {
 
public CoutRevientSQLElement() {
super("COUT_REVIENT");
}
 
protected List<String> getListFields() {
final List<String> list = new ArrayList<String>(2);
list.add("CODE");
list.add("NOM");
list.add("POURCENT");
return list;
}
 
protected List<String> getComboFields() {
final List<String> list = new ArrayList<String>(2);
list.add("CODE");
list.add("NOM");
list.add("POURCENT");
return list;
}
 
@Override
public ListMap<String, String> getShowAs() {
return ListMap.singleton(null, "CODE");
 
}
 
public SQLComponent createComponent() {
return new BaseSQLComponent(this) {
 
public void addViews() {
this.setLayout(new GridBagLayout());
final GridBagConstraints c = new DefaultGridBagConstraints();
 
// Code
final JLabel labelCode = new JLabel(getLabelFor("CODE"));
c.weightx = 0;
this.add(labelCode, c);
c.gridx++;
c.weightx = 1;
final JTextField textCode = new JTextField();
this.add(textCode, c);
 
// Nom
c.gridx++;
c.weightx = 0;
final JLabel labelNom = new JLabel(getLabelFor("NOM"));
this.add(labelNom, c);
c.gridx++;
c.weightx = 1;
final JTextField textNom = new JTextField();
this.add(textNom, c);
 
// Famille
c.gridy++;
c.gridx = 0;
c.weightx = 0;
 
final JLabel labelTaux = new JLabel(getLabelFor("POURCENT"));
this.add(labelTaux, c);
c.gridx++;
c.weightx = 1;
final JTextField textTaux = new JTextField();
this.add(textTaux, c);
 
this.addRequiredSQLObject(textTaux, "POURCENT");
this.addRequiredSQLObject(textNom, "NOM");
this.addRequiredSQLObject(textCode, "CODE");
}
};
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ArticleDesignationSQLElement.java
99,6 → 99,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".name";
return createCodeOfPackage() + ".name";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ArticleTarifSQLElement.java
72,6 → 72,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".price";
return createCodeOfPackage() + ".price";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ArticleCodeClientSQLElement.java
77,7 → 77,7
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".customcode";
return createCodeOfPackage() + ".customcode";
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/FamilleArticleSQLElement.java
201,6 → 201,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".family";
return createCodeOfPackage() + ".family";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/SupplierPriceListSQLElement.java
New file
0,0 → 1,62
/*
* 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.sales.product.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 SupplierPriceListSQLElement extends ComptaSQLConfElement {
public static final String ELEMENT_CODE = "supplier.pricelist";
 
public SupplierPriceListSQLElement() {
super("ARTICLE_TARIF_FOURNISSEUR");
}
 
@Override
protected String createCode() {
return ELEMENT_CODE;
}
 
@Override
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("ID_FOURNISSEUR");
l.add("QTE");
return l;
}
 
@Override
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("ID_FOURNISSEUR");
return l;
}
 
@Override
protected String getParentFFName() {
return "ID_ARTICLE";
}
 
@Override
protected SQLComponent createComponent() {
// TODO Auto-generated method stub
return null;
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ArticleSQLElement.java
18,11 → 18,13
import org.openconcerto.erp.model.PrixHT;
import org.openconcerto.erp.model.PrixTTC;
import org.openconcerto.erp.preferences.DefaultNXProps;
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.ElementSQLObject;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.preferences.SQLPreferences;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.GestionDevise;
50,8 → 52,9
super("ARTICLE", "un article", "articles");
}
 
@Override
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
final List<String> l = new ArrayList<>();
 
l.add("CODE");
l.add("NOM");
65,7 → 68,11
l.add("VALEUR_METRIQUE_3");
l.add("PRIX_METRIQUE_HA_1");
l.add("PRIX_METRIQUE_VT_1");
SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
 
if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
l.add("ID_STOCK");
}
 
String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
Boolean b = Boolean.valueOf(val);
75,8 → 82,9
return l;
}
 
@Override
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
final List<String> l = new ArrayList<>(2);
l.add("CODE");
l.add("NOM");
return l;
95,8 → 103,7
private JTextField textNom, textCode;
private JTextField textPoids;
private DocumentListener htDocListener, ttcDocListener;
private PropertyChangeListener taxeListener;
final ElementComboBox comboSelTaxe = new ElementComboBox(false);
private final ElementComboBox comboSelTaxe = new ElementComboBox(false);
 
public void addViews() {
 
136,7 → 143,7
 
};
 
this.taxeListener = new PropertyChangeListener() {
PropertyChangeListener taxeListener = new PropertyChangeListener() {
 
public void propertyChange(PropertyChangeEvent evt) {
 
229,7 → 236,7
 
this.textPVHT.getDocument().addDocumentListener(this.htDocListener);
this.textPVTTC.getDocument().addDocumentListener(this.ttcDocListener);
this.comboSelTaxe.addValueListener(this.taxeListener);
this.comboSelTaxe.addValueListener(taxeListener);
}
 
private void setTextHT() {
268,4 → 275,9
}
};
}
 
@Override
protected String createCode() {
return "sales.product";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ArticleFournisseurSecondaireSQLElement.java
New file
0,0 → 1,89
/*
* 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.sales.product.element;
 
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JLabel;
import javax.swing.SwingConstants;
 
public class ArticleFournisseurSecondaireSQLElement extends ComptaSQLConfElement {
 
public ArticleFournisseurSecondaireSQLElement() {
super("ARTICLE_FOURNISSEUR_SECONDAIRE", "une liaison article fournisseur", "liaisons article fournisseur");
}
 
protected List<String> getListFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("ID_FOURNISSEUR");
return l;
}
 
protected List<String> getComboFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_ARTICLE");
l.add("ID_FOURNISSEUR");
return l;
}
 
@Override
protected String getParentFFName() {
return "ID_ARTICLE";
}
 
/*
* (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();
 
// Famille père
final JLabel labelLangue = new JLabel(getLabelFor("ID_ARTICLE"), SwingConstants.RIGHT);
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(labelLangue, c);
 
final ElementComboBox artBox = new ElementComboBox(true, 25);
DefaultGridBagConstraints.lockMinimumSize(artBox);
c.gridx++;
c.weightx = 1;
this.add(artBox, c);
 
this.addSQLObject(artBox, "ID_ARTICLE");
}
 
};
}
 
@Override
protected String createCode() {
return createCodeOfPackage() + ".supplier";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ReliquatSQLElement.java
48,7 → 48,7
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".reliquatbr";
return createCodeOfPackage() + ".reliquatbr";
}
}
 
187,6 → 187,6
 
@Override
protected String createCode() {
return createCodeFromPackage() + ".reliquatbl";
return createCodeOfPackage() + ".reliquatbl";
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/action/ListeDesArticlesAction.java
22,13 → 22,14
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.FieldPath;
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.model.graph.Path;
import org.openconcerto.sql.preferences.SQLPreferences;
import org.openconcerto.sql.request.ListSQLRequest;
import org.openconcerto.sql.request.UpdateBuilder;
import org.openconcerto.sql.view.ListeAddPanel;
52,6 → 53,7
import java.beans.PropertyChangeListener;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
82,8 → 84,10
final FamilleArticlePanel panelFam = new FamilleArticlePanel(elt.getForeignElement("ID_FAMILLE_ARTICLE"));
 
final SQLTableModelSourceOnline createTableSource = elt.createTableSource();
SQLPreferences prefs = SQLPreferences.getMemCached(elt.getTable().getDBRoot());
 
SQLTableModelColumn colStock;
SQLTableModelColumn colStock = null;
// if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
if (elt.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
colStock = createTableSource.getColumn(createTableSource.getColumns().size() - 2);
} else {
120,7 → 124,7
colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
createTableSource.getColumns().add(colStock);
}
// createTableSource.getColumns().add(colStock);
// }
final IListe liste = new IListe(createTableSource);
 
final ListeAddPanel panel = new ListeAddPanel(elt, liste) {
131,7 → 135,7
GridBagConstraints c = new DefaultGridBagConstraints();
c.gridwidth = 2;
panel.add(new JLabel("Voulez vous supprimer ou rendre obsoléte?"), c);
JButton buttonObs = new JButton("Obsoléte");
JButton buttonObs = new JButton("Obsolète");
JButton buttonSuppr = new JButton("Supprimer");
c.gridy++;
panel.add(buttonObs, c);
205,6 → 209,9
// });
// }
// }
 
if (colStock != null) {
// && !prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(1);
fields.add(Tuple2.create(colStock, IListTotalPanel.Type.SOMME));
 
215,7 → 222,7
c2.weightx = 0;
c2.fill = GridBagConstraints.NONE;
panel.add(total, c2);
 
}
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(panelFam), panel);
JPanel panelAll = new JPanel(new GridBagLayout());
GridBagConstraints c = new DefaultGridBagConstraints();
300,18 → 307,20
if (panel.getCheckObsolete().isSelected()) {
w = new Where(this.sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
 
w = w.or(new Where(request.getAlias(this.sqlTableArticle.getForeignTable("ID_STOCK").getField("QTE_REEL")), ">", 0));
// FIXME Fonctionnement avec multidepot
// w = w.or(new
// Where(request.getAlias(this.sqlTableArticle.getForeignTable("ID_STOCK").getField("QTE_REEL")),
// ">", 0));
}
 
if (id > 1) {
SQLRow row = this.sqlTableFamilleArticle.getRow(id);
Set<Integer> idsMatch = new HashSet<>();
idsMatch.add(id);
 
fillChildren(idsMatch, CollectionUtils.createSet(id));
 
Where w2 = new Where(this.sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", this.sqlTableFamilleArticle.getKey());
 
String code = row.getString("CODE") + ".%";
final Where w3 = new Where(this.sqlTableFamilleArticle.getField("CODE"), "LIKE", code);
w2 = w2.and(w3.or(new Where(this.sqlTableFamilleArticle.getKey(), "=", id)));
 
w2 = w2.and(new Where(this.sqlTableFamilleArticle.getKey(), idsMatch));
if (w != null) {
w = w.and(w2);
} else {
321,4 → 330,23
}
return w;
}
 
private void fillChildren(Set<Integer> idsMatch, Set<Integer> father) {
SQLRowValues rowVals = new SQLRowValues(this.sqlTableFamilleArticle);
final String keyFieldName = rowVals.getTable().getKey().getName();
rowVals.put(keyFieldName, null);
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
List<SQLRowValues> children = fetcher.fetch(new Where(this.sqlTableFamilleArticle.getField("ID_FAMILLE_ARTICLE_PERE"), father));
Set<Integer> childToCheck = new HashSet<>();
for (SQLRowValues child : children) {
if (!idsMatch.contains(child.getID())) {
childToCheck.add(child.getID());
idsMatch.add(child.getID());
}
}
if (!childToCheck.isEmpty()) {
fillChildren(idsMatch, childToCheck);
}
 
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/action/InventairePanel.java
14,6 → 14,7
package org.openconcerto.erp.core.sales.product.action;
 
import org.openconcerto.erp.core.common.ui.NumericTextField;
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
import org.openconcerto.erp.core.supplychain.stock.element.StockItem.TypeStockMouvement;
21,7 → 22,6
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.SQLTable;
import org.openconcerto.sql.utils.SQLUtils;
import org.openconcerto.sql.view.list.IListe;
60,7 → 60,7
private final String mvtStockTableQuoted;
private static String defaultLabel = "Mise à jour des stocks";
 
public InventairePanel(final IListe liste, final List<? extends SQLRowAccessor> articles) {
public InventairePanel(final IListe liste, final List<? extends SQLRowAccessor> stocks) {
super(new GridBagLayout());
final SQLTable mvtStockTable = Configuration.getInstance().getRoot().findTable("MOUVEMENT_STOCK");
this.mvtStockTableQuoted = mvtStockTable.getSQLName().quote();
158,16 → 158,14
fieldReel.getDocument().addDocumentListener(l);
fieldRecpAtt.getDocument().addDocumentListener(l);
 
if (articles.size() == 1) {
SQLRowAccessor r = articles.get(0);
if (!r.isForeignEmpty("ID_STOCK")) {
SQLRowAccessor stock = r.getForeign("ID_STOCK");
if (stocks.size() == 1) {
SQLRowAccessor r = stocks.get(0);
SQLRowAccessor stock = r;
fieldReel.setText(String.valueOf(stock.getFloat("QTE_REEL")));
fieldLivAtt.setText(String.valueOf(stock.getFloat("QTE_LIV_ATTENTE")));
fieldRecpAtt.setText(String.valueOf(stock.getFloat("QTE_RECEPT_ATTENTE")));
fieldTh.setText(String.valueOf(stock.getFloat("QTE_TH")));
}
}
 
c.gridy++;
c.gridx = 0;
202,14 → 200,21
List<List<String>> multipleRequests = new ArrayList<List<String>>();
List<String> multipleRequestsHundred = new ArrayList<String>(100);
boolean usePrice = mvtStockTable.contains("PRICE");
 
List<StockItem> stockItems = new ArrayList<StockItem>();
final Date dateValue = date.getValue();
for (SQLRowAccessor sqlRowAccessor : articles) {
for (SQLRowAccessor sqlRowAccessor : stocks) {
if (multipleRequestsHundred.size() > 100) {
multipleRequests.add(multipleRequestsHundred);
multipleRequestsHundred = new ArrayList<String>(100);
}
StockItem item = new StockItem(sqlRowAccessor);
StockItem item = new StockItem(sqlRowAccessor.getForeign("ID_ARTICLE"), sqlRowAccessor);
if (!item.isStockInit()) {
((ReferenceArticleSQLElement) liste.getSource().getElem().getDirectory().getElement("ARTICLE")).initStock(sqlRowAccessor.getForeignID("ID_ARTICLE"));
SQLRow rowArticle = sqlRowAccessor.getForeign("ID_ARTICLE").asRow();
rowArticle.fetchValues();
item = new StockItem(rowArticle, rowArticle.getForeign("ID_STOCK"));
}
stockItems.add(item);
boolean modified = false;
if (qteReel != null && !NumberUtils.areNumericallyEqual(qteReel, item.getRealQty())) {
double diff = qteReel.doubleValue() - item.getRealQty();
235,20 → 240,9
if (item.isStockInit()) {
multipleRequestsHundred.add(item.getUpdateRequest());
} else {
SQLRowValues rowVals = new SQLRowValues(sqlRowAccessor.getTable().getForeignTable("ID_STOCK"));
rowVals.put("QTE_REEL", item.getRealQty());
rowVals.put("QTE_TH", item.getVirtualQty());
rowVals.put("QTE_LIV_ATTENTE", item.getDeliverQty());
rowVals.put("QTE_RECEPT_ATTENTE", item.getReceiptQty());
SQLRowValues rowValsArt = item.getArticle().createEmptyUpdateRow();
rowValsArt.put("ID_STOCK", rowVals);
try {
rowValsArt.commit();
} catch (SQLException e1) {
e1.printStackTrace();
throw new IllegalStateException();
}
}
}
 
}
multipleRequests.add(multipleRequestsHundred);
269,12 → 263,12
 
final DBRoot root = mvtStockTable.getDBRoot();
if (root.contains("ARTICLE_ELEMENT")) {
List<StockItem> stockItems = new ArrayList<StockItem>();
for (SQLRowAccessor sqlRowAccessor2 : articles) {
final SQLRow asRow = sqlRowAccessor2.asRow();
asRow.fetchValues();
stockItems.add(new StockItem(asRow));
}
// List<StockItem> stockItems = new ArrayList<StockItem>();
// for (SQLRowAccessor sqlRowAccessor2 : stocks) {
// final SQLRow asRow = sqlRowAccessor2.asRow();
// asRow.fetchValues();
// stockItems.add(new StockItem(asRow));
// }
// Mise à jour des stocks des nomenclatures
ComposedItemStockUpdater comp = new ComposedItemStockUpdater(root, stockItems);
try {
292,14 → 286,14
 
private String getMvtRequest(Date time, BigDecimal prc, double qteFinal, StockItem item, String label, boolean reel, boolean usePrice) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"NOM\",\"REEL\",\"ORDRE\"";
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"NOM\",\"REEL\",\"ORDRE\"";
 
if (usePrice && prc != null) {
mvtStockQuery += ",\"PRICE\"";
}
 
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + item.getArticle().getID() + ",'" + label + "'," + reel + ", (SELECT (MAX(\"ORDRE\")+1) FROM "
+ mvtStockTableQuoted + ")";
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + item.getArticle().getID() + "," + item.stock.getID() + ",'" + label + "'," + reel
+ ", (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
if (usePrice && prc != null) {
mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/ArticleTarifTable.java
29,6 → 29,7
import org.openconcerto.sql.view.list.RowValuesTableModel;
import org.openconcerto.sql.view.list.RowValuesTablePanel;
import org.openconcerto.sql.view.list.SQLTableElement;
import org.openconcerto.ui.table.NumberCellRenderer;
import org.openconcerto.utils.DecimalUtils;
 
import java.math.BigDecimal;
121,6 → 122,16
this.defaultRowVals.put("PRIX_METRIQUE_VT_1", BigDecimal.ZERO);
this.defaultRowVals.put("PV_HT", BigDecimal.ZERO);
this.defaultRowVals.put("PV_TTC", BigDecimal.ZERO);
if (e.getTable().contains("POURCENT_REMISE")) {
final SQLTableElement tableElementDiscount = new SQLTableElement(e.getTable().getField("POURCENT_REMISE"), BigDecimal.class) {
@Override
protected Object getDefaultNullValue() {
return BigDecimal.ZERO;
}
};
tableElementDiscount.setRenderer(new NumberCellRenderer());
list.add(tableElementDiscount);
}
this.model = new RowValuesTableModel(e, list, e.getTable().getField("ID_TARIF"), false, this.defaultRowVals);
 
this.table = new RowValuesTable(this.model, null);
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/GestionArticlePreferencePanel.java
36,7 → 36,7
 
private final JCheckBox checkModeVente, checkLongueur, checkLargeur, checkPoids;
private final JCheckBox checkService, checkVenteComptoir, checkShowPoids, checkShowStyle, checkSFE;
private final JCheckBox checkDevise, checkMarge;
private final JCheckBox checkMarge;
private JCheckBox checkSite;
 
public GestionArticlePreferencePanel() {
55,12 → 55,9
this.checkModeVente = new JCheckBox("Activer le mode de vente spécifique");
this.checkVenteComptoir = new JCheckBox("Activer le mode vente comptoir");
this.checkShowPoids = new JCheckBox("Voir le Poids");
this.checkDevise = new JCheckBox("Gérer les devises");
this.checkMarge = new JCheckBox("Afficher le taux de marque au lieu du taux de marge");
 
 
this.add(this.checkDevise, c);
c.gridy++;
this.add(this.checkMarge, c);
c.gridy++;
this.add(this.checkService, c);
109,7 → 106,6
props.setProperty("ShowSiteFacture", String.valueOf(this.checkSite.isSelected()));
}
props.setProperty("ArticleVenteComptoir", String.valueOf(this.checkVenteComptoir.isSelected()));
props.setProperty(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE, String.valueOf(this.checkDevise.isSelected()));
props.setProperty(TotalPanel.MARGE_MARQUE, String.valueOf(this.checkMarge.isSelected()));
props.store();
}
123,7 → 119,6
this.checkService.setSelected(true);
this.checkSFE.setSelected(false);
this.checkVenteComptoir.setSelected(true);
this.checkDevise.setSelected(false);
this.checkMarge.setSelected(false);
if (this.checkSite != null) {
this.checkSite.setSelected(false);
172,8 → 167,6
// Show Style
this.checkShowStyle.setSelected(props.getBooleanValue("ArticleShowStyle", false));
 
// Devise
this.checkDevise.setSelected(props.getBooleanValue(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE, false));
 
// Devise
this.checkMarge.setSelected(props.getBooleanValue(TotalPanel.MARGE_MARQUE, false));
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/ArticleFournisseurSecondaireTable.java
New file
0,0 → 1,62
/*
* 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.sales.product.ui;
 
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLTable;
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.util.List;
import java.util.Vector;
 
public class ArticleFournisseurSecondaireTable extends RowValuesTablePanel {
 
private SQLTable article = Configuration.getInstance().getBase().getTable("ARTICLE");
 
public ArticleFournisseurSecondaireTable() {
 
init();
uiInit();
 
}
 
/**
*
*/
protected void init() {
 
final SQLElement e = getSQLElement();
 
final List<SQLTableElement> list = new Vector<SQLTableElement>();
 
SQLTableElement f = new SQLTableElement(e.getTable().getField("ID_FOURNISSEUR"));
f.setEditable(false);
list.add(f);
 
this.defaultRowVals = new SQLRowValues(getSQLElement().getTable());
this.model = new RowValuesTableModel(e, list, e.getTable().getField("ID_FOURNISSEUR"), false, this.defaultRowVals);
 
this.table = new RowValuesTable(this.model, null);
}
 
public SQLElement getSQLElement() {
return Configuration.getInstance().getDirectory().getElement("ARTICLE_FOURNISSEUR_SECONDAIRE");
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/ArticleCategorieComptableTable.java
New file
0,0 → 1,80
/*
* 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.sales.product.ui;
 
import org.openconcerto.erp.core.common.ui.DeviseNumericHTConvertorCellEditor;
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLTable;
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 org.openconcerto.utils.DecimalUtils;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Vector;
 
public class ArticleCategorieComptableTable extends RowValuesTablePanel {
 
private SQLTableElement cat;
private SQLTable article = Configuration.getInstance().getBase().getTable("ARTICLE");
 
public ArticleCategorieComptableTable() {
 
init();
uiInit();
 
}
 
/**
*
*/
protected void init() {
 
final SQLElement e = getSQLElement();
 
final List<SQLTableElement> list = new Vector<SQLTableElement>();
 
this.cat = new SQLTableElement(e.getTable().getField("ID_CATEGORIE_COMPTABLE"));
this.cat.setEditable(false);
list.add(this.cat);
 
list.add(new SQLTableElement(e.getTable().getField("ID_COMPTE_PCE_VENTE")));
 
list.add(new SQLTableElement(e.getTable().getField("ID_TAXE_VENTE")));
list.add(new SQLTableElement(e.getTable().getField("ID_COMPTE_PCE_ACHAT")));
 
list.add(new SQLTableElement(e.getTable().getField("ID_TAXE_ACHAT")));
 
this.defaultRowVals = new SQLRowValues(getSQLElement().getTable());
this.model = new RowValuesTableModel(e, list, e.getTable().getField("ID_CATEGORIE_COMPTABLE"), false, this.defaultRowVals);
 
this.table = new RowValuesTable(this.model, null);
}
 
public SQLElement getSQLElement() {
return Configuration.getInstance().getDirectory().getElement("ARTICLE_CATEGORIE_COMPTABLE");
}
 
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/model/ProductComponent.java
14,13 → 14,19
package org.openconcerto.erp.core.sales.product.model;
 
import org.openconcerto.erp.core.sales.product.model.ProductHelper.SupplierPriceField;
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
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.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.ExceptionHandler;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
29,13 → 35,17
 
public class ProductComponent {
private final SQLRowAccessor product;
private final SQLRowAccessor source;
private final SQLRowAccessor stock;
private BigDecimal qty;
private final ProductHelper helper;
 
public ProductComponent(SQLRowAccessor product, BigDecimal qty) {
public ProductComponent(SQLRowAccessor product, BigDecimal qty, SQLRowAccessor source, SQLRowAccessor stock) {
this.product = product;
this.qty = qty;
this.helper = new ProductHelper(product.getTable().getDBRoot());
this.source = source;
this.stock = stock;
}
 
public SQLRowAccessor getProduct() {
42,6 → 52,14
return product;
}
 
public SQLRowAccessor getSource() {
return source;
}
 
public SQLRowAccessor getStock() {
return stock;
}
 
public BigDecimal getQty() {
return qty;
}
80,6 → 98,8
result = PriceByQty.getPriceForQty(qty.setScale(0, RoundingMode.HALF_UP).intValue(), prices, d);
if (result == null) {
result = PriceByQty.getPriceForQty(qty.setScale(0, RoundingMode.HALF_UP).intValue(), prices, lastDate);
} else if (prices.size() > 0) {
result = prices.get(0).getPrice();
}
}
if (result == null) {
112,16 → 132,87
return null;
}
 
public static ProductComponent createFromRowArticle(SQLRowAccessor rowArticle, SQLRowAccessor rowValsSource) {
SQLRowAccessor rowStock = getStock(rowArticle, rowArticle, rowValsSource);
 
return new ProductComponent(rowArticle, BigDecimal.ONE, rowValsSource, rowStock);
}
 
public static ProductComponent createFrom(SQLRowAccessor rowVals) {
return createFrom(rowVals, 1);
return createFrom(rowVals, 1, rowVals);
}
 
public static ProductComponent createFrom(SQLRowAccessor rowVals, int qteMultiple) {
public static ProductComponent createFrom(SQLRowAccessor rowVals, SQLRowAccessor rowValsSource) {
return createFrom(rowVals, 1, rowValsSource);
}
 
public static ProductComponent createFrom(SQLRowAccessor rowVals, int qteMultiple, SQLRowAccessor rowValsSource) {
 
if (rowVals.getForeign("ID_ARTICLE") == null || rowVals.isForeignEmpty("ID_ARTICLE")) {
throw new IllegalArgumentException("Aucun article associé à la row " + rowVals.getTable().getName() + " " + rowVals.getID());
}
final int qteMult = (rowVals.getTable().getName().equalsIgnoreCase("BON_DE_LIVRAISON_ELEMENT") ? rowVals.getInt("QTE_LIVREE") : rowVals.getInt("QTE"));
final int qte = qteMult * qteMultiple;
final BigDecimal qteUV = rowVals.getBigDecimal("QTE_UNITAIRE");
BigDecimal qteFinal = qteUV.multiply(new BigDecimal(qte), DecimalUtils.HIGH_PRECISION);
return new ProductComponent(rowVals.getForeign("ID_ARTICLE"), qteFinal);
SQLRowAccessor rowStock = getStock(rowVals.getForeign("ID_ARTICLE"), rowVals, rowValsSource);
 
// }
// else {
// rowStock = rowVals.getForeign("ID_ARTICLE").getForeign("ID_STOCK");
// }
return new ProductComponent(rowVals.getForeign("ID_ARTICLE"), qteFinal, rowValsSource, rowStock);
// return new ProductComponent(rowVals.getForeign("ID_ARTICLE"), qteFinal);
}
 
private static SQLRowAccessor getStock(SQLRowAccessor rowValsProduct, SQLRowAccessor rowValsElt, SQLRowAccessor rowValsSource) {
SQLRowAccessor rowStock = null;
final int idDepot;
if (rowValsSource.getFields().contains("ID_DEPOT_STOCK") && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
} else {
if (rowValsElt.getForeign("ID_DEPOT_STOCK") != null && !rowValsElt.isForeignEmpty("ID_DEPOT_STOCK")) {
idDepot = rowValsElt.getForeignID("ID_DEPOT_STOCK");
} else {
idDepot = DepotStockSQLElement.DEFAULT_ID;
try {
rowValsElt.createEmptyUpdateRow().put("ID_DEPOT_STOCK", idDepot).commit();
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors de l'initialisation du stock!", e);
}
 
}
}
 
SQLTable stockTable = rowValsElt.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"), "=", rowValsProduct.getID());
Collection<SQLRowValues> rowValsResult = fetch.fetch(w.and(w2));
if (rowValsResult.size() == 0) {
SQLRowValues rowValsStock = new SQLRowValues(stockTable);
rowValsStock.put("ID_ARTICLE", rowValsProduct.getID());
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) {
rowValsProduct.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 " + rowValsProduct.getID() + " Depot " + rowValsElt.getForeignID("ID_DEPOT_STOCK"));
}
return rowStock;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/model/PriceByQty.java
56,6 → 56,9
});
for (PriceByQty priceByQty : list) {
if (priceByQty.qty > qty) {
if (result == null) {
result = priceByQty.price;
}
break;
}
if (result == null || priceByQty.startDate.before(d)) {
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/model/ProductHelper.java
24,6 → 24,7
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.ListMap;
import org.openconcerto.utils.cc.ITransformer;
 
import java.math.BigDecimal;
211,11 → 212,12
return getChildWithQtyFrom(items, new HashSet<Integer>());
}
 
private List<ProductComponent> getChildWithQtyFrom(List<ProductComponent> items, Set<Integer> ancestors) {
private List<ProductComponent> getChildWithQtyFrom(List<ProductComponent> items, Set<Integer> ancestorsOrigin) {
 
if (root.contains("ARTICLE_ELEMENT")) {
 
int originalAncestorsSize = ancestors.size();
int originalAncestorsSize = ancestorsOrigin.size();
Set<Integer> ancestors = new HashSet<Integer>(ancestorsOrigin);
 
List<ProductComponent> result = new ArrayList<ProductComponent>();
 
222,17 → 224,22
// liste des ids parents
final List<Integer> parentsArticleIDs = new ArrayList<Integer>();
 
// ID Article -- component
ListMap<Integer, ProductComponent> productCompByID = new ListMap<Integer, ProductComponent>();
 
// Quantité par parents
Map<Integer, ProductComponent> productCompByID = new HashMap<Integer, ProductComponent>();
final Map<Integer, BigDecimal> qtyParent = new HashMap<Integer, BigDecimal>();
// final ListMap<Integer, BigDecimal> qtyParentIDSource = new HashMap<Integer,
// BigDecimal>();
for (ProductComponent p : items) {
parentsArticleIDs.add(p.getProduct().getID());
BigDecimal qty = BigDecimal.ZERO;
if (qtyParent.get(p.getProduct().getID()) != null) {
qty = qtyParent.get(p.getProduct().getID());
productCompByID.add(p.getProduct().getID(), p);
int idSource = p.getProduct().getID();
parentsArticleIDs.add(idSource);
// BigDecimal qty = BigDecimal.ZERO;
// if (qtyParent.get(idSource) != null) {
// qty = qtyParent.get(idSource);
// }
// qtyParent.put(idSource, qty.add(p.getQty()));
}
qtyParent.put(p.getProduct().getID(), qty.add(p.getQty()));
}
 
// get all childs
final SQLTable costTable = root.getTable("ARTICLE_ELEMENT");
239,8 → 246,10
 
SQLRowValues rowVals = new SQLRowValues(costTable);
 
final SQLRowValues stockRowValues = rowVals.putRowValues("ID_ARTICLE").put("ID", null).put("GESTION_STOCK", null).put("CODE", null).put("NOM", null).putRowValues("ID_STOCK");
stockRowValues.putNulls("QTE_TH", "QTE_RECEPT_ATTENTE", "QTE_REEL", "QTE_LIV_ATTENTE");
final SQLRowValues artRowValues = rowVals.putRowValues("ID_ARTICLE").putNulls("ID", "GESTION_STOCK", "CODE", "NOM", "ID_DEPOT_STOCK", "ID_UNITE_VENTE");
SQLRowValues stockRowVals = new SQLRowValues(root.getTable("STOCK"));
stockRowVals.putNulls("QTE_TH", "QTE_RECEPT_ATTENTE", "QTE_REEL", "QTE_LIV_ATTENTE", "ID_DEPOT_STOCK");
stockRowVals.put("ID_ARTICLE", artRowValues);
rowVals.putRowValues("ID_ARTICLE_PARENT").put("ID", null);
rowVals.put("QTE", null);
rowVals.put("QTE_UNITAIRE", null);
263,22 → 272,33
for (SQLRowValues childRowValues : childs) {
final SQLRowAccessor foreignArticleParent = childRowValues.getForeign("ID_ARTICLE_PARENT");
 
if (!childRowValues.isForeignEmpty("ID_ARTICLE") && childRowValues.getForeign("ID_ARTICLE") != null) {
ProductComponent childComponent = ProductComponent.createFrom(childRowValues);
if (childRowValues.getObject("ID_ARTICLE") != null && !childRowValues.isForeignEmpty("ID_ARTICLE")) {
 
List<ProductComponent> source = productCompByID.get(foreignArticleParent.getID());
// Test pour éviter les boucles dans les boms
if (!ancestors.contains(childComponent.getProduct().getID())) {
if (!ancestorsOrigin.contains(foreignArticleParent.getID())) {
ancestors.add(foreignArticleParent.getID());
for (ProductComponent productParent : source) {
 
final SQLRowAccessor foreignArticle = childRowValues.getForeign("ID_ARTICLE");
ProductComponent childComponent = ProductComponent.createFromRowArticle(foreignArticle, productParent.getSource());
 
// parentsArticleIDs.remove(foreignArticleParent.getID());
// Calcul de la quantité qte_unit * qte * qteMergedParent
childComponent.setQty(childComponent.getQty().multiply(qtyParent.get(foreignArticleParent.getID()), DecimalUtils.HIGH_PRECISION));
childComponent.setQty(childComponent.getQty().multiply(productParent.getQty(), DecimalUtils.HIGH_PRECISION));
 
// Cumul des valeurs si l'article est présent plusieurs fois dans le bom
ProductComponent existProduct = productCompByID.get(childComponent.getProduct().getID());
if (existProduct == null) {
// Cumul des valeurs si l'article est présent plusieurs fois dans le
// bom
// ProductComponent existProduct =
// productCompByID.get(childComponent.getProduct().getID());
// if (existProduct == null) {
// Maintenant on garde une ligne disctincte pour chaque kit
result.add(childComponent);
productCompByID.put(childComponent.getProduct().getID(), childComponent);
} else {
existProduct.addQty(childComponent.getQty());
// productCompByID.put(childComponent.getProduct().getID(),
// childComponent);
// } else {
// existProduct.addQty(childComponent.getQty());
// }
}
}
}
289,34 → 309,34
// Merge des valeurs
for (ProductComponent s : bomFromChilds) {
 
ProductComponent existProduct = productCompByID.get(s.getProduct().getID());
if (existProduct == null) {
// ProductComponent existProduct = productCompByID.get(s.getProduct().getID());
// if (existProduct == null) {
result.add(s);
productCompByID.put(s.getProduct().getID(), s);
} else {
existProduct.addQty(s.getQty());
// productCompByID.put(s.getProduct().getID(), s);
// } else {
// existProduct.addQty(s.getQty());
// }
}
}
}
 
// Ajout des articles présents dans l'ensemble de départ
if (originalAncestorsSize == 0) {
for (ProductComponent p : items) {
ProductComponent existProduct = productCompByID.get(p.getProduct().getID());
if (existProduct == null) {
// ProductComponent existProduct = productCompByID.get(p.getProduct().getID());
// if (existProduct == null) {
result.add(p);
productCompByID.put(p.getProduct().getID(), p);
} else {
existProduct.addQty(p.getQty());
// productCompByID.put(p.getProduct().getID(), p);
// } else {
// existProduct.addQty(p.getQty());
// }
}
}
}
 
// On supprime les ancestors (kits) du result
for (Integer anc : ancestors) {
ProductComponent comp = productCompByID.get(anc);
if (comp != null) {
result.remove(comp);
// ProductComponent comp = productCompByID.get(anc);
if (productCompByID.containsKey(anc)) {
result.removeAll(productCompByID.get(anc));
}
}
 
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/component/ReferenceArticleSQLComponent.java
21,12 → 21,17
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.core.sales.product.element.ArticleCodeClientTable;
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
import org.openconcerto.erp.core.sales.product.element.SupplierPriceListTable;
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
import org.openconcerto.erp.core.sales.product.ui.ArticleCategorieComptableTable;
import org.openconcerto.erp.core.sales.product.ui.ArticleDesignationTable;
import org.openconcerto.erp.core.sales.product.ui.ArticleTarifTable;
import org.openconcerto.erp.core.sales.product.ui.ProductItemListTable;
import org.openconcerto.erp.core.sales.product.ui.ProductQtyPriceListTable;
import org.openconcerto.erp.core.sales.product.ui.RowValuesTableEditionPanel;
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
import org.openconcerto.erp.model.ISQLCompteSelector;
import org.openconcerto.erp.preferences.DefaultNXProps;
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
38,9 → 43,11
import org.openconcerto.sql.model.SQLRowListRSH;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.preferences.SQLPreferences;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.sql.sqlobject.SQLTextCombo;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.FormLayouter;
import org.openconcerto.ui.TitledSeparator;
47,6 → 54,7
import org.openconcerto.ui.component.ITextArea;
import org.openconcerto.ui.preferences.DefaultProps;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.StringUtils;
import org.openconcerto.utils.text.SimpleDocumentListener;
 
61,6 → 69,7
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
97,9 → 106,15
private ArticleDesignationTable tableDes = new ArticleDesignationTable();
private ArticleCodeClientTable tableCodeClient = new ArticleCodeClientTable();
private ArticleTarifTable tableTarifVente = new ArticleTarifTable(this);
private ArticleCategorieComptableTable tableCatComptable = new ArticleCategorieComptableTable();
private SupplierPriceListTable tableFourSec = new SupplierPriceListTable();
 
private ProductQtyPriceListTable tableTarifQteVente = new ProductQtyPriceListTable(this);
private ProductItemListTable tableBom;
private final JTextField textMarge = new JTextField(15);
private final JTextField textMarge = new JTextField(10);
private final JLabel labelMarge = new JLabel("% ");
private ElementComboBox boxCR;
private JCheckBox boxMargeWithCR;
 
private DocumentListener pieceHAArticle = new SimpleDocumentListener() {
 
139,10 → 154,19
ReferenceArticleSQLComponent.this.textMarge.getDocument().removeDocumentListener(ReferenceArticleSQLComponent.this.listenerMargeTextMarge);
if (ReferenceArticleSQLComponent.this.textPVHT.getText().trim().length() > 0 && ReferenceArticleSQLComponent.this.textPAHT.getText().trim().length() > 0) {
final BigDecimal vt = StringUtils.getBigDecimalFromUserText(ReferenceArticleSQLComponent.this.textPVHT.getText());
final BigDecimal ha = StringUtils.getBigDecimalFromUserText(ReferenceArticleSQLComponent.this.textPAHT.getText());
BigDecimal ha = StringUtils.getBigDecimalFromUserText(ReferenceArticleSQLComponent.this.textPAHT.getText());
 
if (vt != null && ha != null) {
if (vt.signum() != 0 && ha.signum() != 0) {
 
if (boxMargeWithCR.isSelected() && boxCR != null) {
SQLRow rowCR = boxCR.getSelectedRow();
if (rowCR != null && !rowCR.isUndefined()) {
BigDecimal cr = rowCR.getBigDecimal("POURCENT");
ha = ha.multiply(cr.movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
}
}
 
BigDecimal margeHT = vt.subtract(ha);
 
BigDecimal value;
162,6 → 186,7
} else {
ReferenceArticleSQLComponent.this.textMarge.setText("0");
}
labelMarge.setText("% (" + StringUtils.leftAlign(margeHT.setScale(2, RoundingMode.HALF_UP).toString(), 9) + ")");
}
}
}
184,18 → 209,34
BigDecimal ha = StringUtils.getBigDecimalFromUserText(this.textPAHT.getText());
if (ha != null && this.textMarge.getText().trim().length() > 0) {
 
if (boxMargeWithCR.isSelected() && boxCR != null) {
SQLRow rowCR = this.boxCR.getSelectedRow();
if (rowCR != null && !rowCR.isUndefined()) {
BigDecimal cr = rowCR.getBigDecimal("POURCENT");
ha = ha.multiply(cr.movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
}
}
 
BigDecimal d = StringUtils.getBigDecimalFromUserText(this.textMarge.getText());
if (d == null) {
d = BigDecimal.ZERO;
}
final BigDecimal vt;
if (DefaultNXProps.getInstance().getBooleanValue(TotalPanel.MARGE_MARQUE, false)) {
final BigDecimal e = BigDecimal.ONE.subtract(d.divide(BigDecimal.valueOf(100), DecimalUtils.HIGH_PRECISION));
if (e.signum() == 0) {
this.textPVHT.setText("0");
vt = BigDecimal.ZERO;
} else {
this.textPVHT.setText(ha.divide(e, DecimalUtils.HIGH_PRECISION).setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
vt = ha.divide(e, DecimalUtils.HIGH_PRECISION).setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP);
}
} else {
BigDecimal result = ha.multiply(d.divide(BigDecimal.valueOf(100), DecimalUtils.HIGH_PRECISION).add(BigDecimal.ONE));
this.textPVHT.setText(result.setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
vt = result.setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP);
this.textPVHT.setText(vt.toString());
}
this.textPVHT.setText(vt.toString());
BigDecimal margeHT = vt.subtract(ha);
labelMarge.setText("% (" + StringUtils.leftAlign(margeHT.setScale(2, RoundingMode.HALF_UP).toString(), 9) + ")");
}
}
}
214,6 → 255,8
this.checkObs.setVisible(true);
this.tableTarifVente.setArticleValues(r);
this.tableTarifVente.insertFrom("ID_ARTICLE", r.getID());
this.tableCatComptable.insertFrom("ID_ARTICLE", r.getID());
this.tableFourSec.insertFrom("ID_ARTICLE", r.getID());
this.tableTarifQteVente.insertFrom("ID_ARTICLE", r.getID());
if (this.tableBom != null) {
this.tableBom.insertFrom("ID_ARTICLE_PARENT", r.getID());
306,6 → 349,7
// Gestion des unités de vente
final boolean gestionUV = prefs.getBoolean(GestionArticleGlobalPreferencePanel.UNITE_VENTE, true);
c.gridy++;
final ElementComboBox boxUnite = new ElementComboBox();
if (gestionUV) {
c.gridx = 0;
c.weightx = 0;
313,7 → 357,6
c.gridx++;
c.weightx = 1;
c.fill = GridBagConstraints.NONE;
ElementComboBox boxUnite = new ElementComboBox();
DefaultGridBagConstraints.lockMinimumSize(boxUnite);
this.add(boxUnite, c);
this.addView(boxUnite, "ID_UNITE_VENTE");
330,6 → 373,35
this.addView(fieldSKU, "SKU");
c.fill = GridBagConstraints.HORIZONTAL;
 
c.gridy++;
if (gestionUV) {
c.gridx = 0;
c.weightx = 0;
this.add(new JLabel(getLabelFor("QTE_UNITAIRE"), SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1;
c.fill = GridBagConstraints.NONE;
final JTextField qte = new JTextField(10);
qte.setEditable(false);
 
this.add(qte, c);
this.addView(qte, "QTE_UNITAIRE", REQ);
boxUnite.addModelListener("wantedID", new PropertyChangeListener() {
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!boxUnite.isEmpty() && boxUnite.getSelectedId() == UniteVenteArticleSQLElement.A_LA_PIECE) {
qte.setText("1");
qte.setEditable(false);
} else {
qte.setEditable(true);
}
 
}
});
c.fill = GridBagConstraints.HORIZONTAL;
}
 
DefaultProps props = DefaultNXProps.getInstance();
 
// Article détaillé
460,8 → 532,19
ElementComboBox boxTaxeCompl = new ElementComboBox();
panel.add(boxTaxeCompl, c);
 
c.weightx = 0;
c.gridy++;
c.gridx = 0;
JLabel labelMatiere = new JLabel(getLabelFor("MATIERE"));
c.fill = GridBagConstraints.BOTH;
panel.add(labelMatiere, c);
c.weightx = 1;
c.gridx++;
SQLTextCombo comboMatiere = new SQLTextCombo();
panel.add(comboMatiere, c);
 
c.gridy++;
c.gridx = 0;
c.gridwidth = GridBagConstraints.REMAINDER;
TitledSeparator sep = new TitledSeparator(getLabelFor("INFOS"));
panel.add(sep, c);
472,6 → 555,7
panel.add(infos, c);
 
this.addSQLObject(infos, "INFOS");
this.addSQLObject(comboMatiere, "MATIERE");
this.addSQLObject(box, "ID_ECO_CONTRIBUTION");
this.addSQLObject(boxTaxeCompl, "ID_TAXE_COMPLEMENTAIRE");
return panel;
640,17 → 724,31
}
});
 
c.gridwidth = 1;
if (gestionStockMin) {
boolean visibleDepot = (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false));
c.gridx = 0;
c.gridy++;
c.weightx = 0;
panel.add(new JLabel(getLabelFor("QTE_MIN")), c);
final JLabel labelDepot = new JLabel(getLabelFor("ID_DEPOT_STOCK"));
panel.add(labelDepot, c);
labelDepot.setVisible(visibleDepot);
c.gridx++;
c.weightx = 1;
panel.add(fieldQteMin, c);
this.addView(fieldQteMin, "QTE_MIN");
ElementComboBox boxDepot = new ElementComboBox();
panel.add(boxDepot, c);
boxDepot.setVisible(visibleDepot);
this.addView(boxDepot, "ID_DEPOT_STOCK", REQ);
 
c.gridwidth = 1;
if (gestionStockMin) {
// c.gridx = 0;
// c.gridy++;
// c.weightx = 0;
// panel.add(new JLabel(getLabelFor("QTE_MIN")), c);
// c.gridx++;
// c.weightx = 1;
// panel.add(fieldQteMin, c);
// this.addView(fieldQteMin, "QTE_MIN");
 
c.gridx = 0;
c.gridy++;
c.weightx = 0;
700,12 → 798,16
this.addView(selAchat, "ID_COMPTE_PCE_ACHAT");
 
c.gridy++;
c.gridx = 0;
c.weighty = 1;
c.weightx = 1;
c.fill = GridBagConstraints.BOTH;
final JPanel spacer = new JPanel();
spacer.setOpaque(false);
panel.add(spacer, c);
c.gridwidth = GridBagConstraints.REMAINDER;
 
panel.add(createCategorieComptablePanel(), c);
// final JPanel spacer = new JPanel();
// spacer.setOpaque(false);
// panel.add(spacer, c);
return panel;
}
 
752,14 → 854,86
}
});
} else {
 
// Tarif fournisseur
c.gridy++;
c.gridx = 0;
c.gridwidth = GridBagConstraints.REMAINDER;
TitledSeparator sep = new TitledSeparator("Tarifs fournisseurs");
panel.add(sep, c);
 
// Ajout fournisseur
c.gridwidth = 1;
c.weightx = 0;
c.gridy++;
c.gridx = 0;
panel.add(new JLabel("Ajouter le fournisseur "), c);
 
final ElementComboBox boxF = new ElementComboBox();
boxF.init(Configuration.getInstance().getDirectory().getElement("FOURNISSEUR"));
 
c.gridx++;
panel.add(boxF, c);
 
c.fill = GridBagConstraints.NONE;
c.gridx++;
JButton buttonAjouter = new JButton("Ajouter");
buttonAjouter.setOpaque(false);
panel.add(buttonAjouter, c);
c.gridx++;
JButton buttonSupprimer = new JButton("Supprimer");
buttonSupprimer.setOpaque(false);
panel.add(buttonSupprimer, c);
 
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
c.weightx = 1;
c.gridy++;
c.gridx = 0;
c.fill = GridBagConstraints.BOTH;
final JPanel spacer = new JPanel();
spacer.setOpaque(false);
panel.add(spacer, c);
this.tableFourSec.setOpaque(false);
panel.add(this.tableFourSec, c);
 
// Listeners
buttonAjouter.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
 
SQLRow rowCat = boxF.getSelectedRow();
if (rowCat == null || rowCat.isUndefined()) {
return;
}
int nbRows = tableFourSec.getModel().getRowCount();
 
// for (int i = 0; i < nbRows; i++) {
// SQLRowValues rowVals = tableFourSec.getModel().getRowValuesAt(i);
// int idTarif =
// Integer.parseInt(rowVals.getObject("ID_FOURNISSEUR").toString());
// if (idTarif == rowCat.getID()) {
// JOptionPane.showMessageDialog(null, "Impossible d'ajouter.\nLe fournisseur
// est déjà présent dans la liste!");
// return;
// }
// }
 
SQLRowValues rowVals = new SQLRowValues(Configuration.getInstance().getBase().getTable("ARTICLE_TARIF_FOURNISSEUR"));
if (getSelectedID() > 1) {
rowVals.put("ID_ARTICLE", getSelectedID());
}
rowVals.put("ID_FOURNISSEUR", rowCat.getID());
tableFourSec.getModel().addRow(rowVals);
}
});
buttonSupprimer.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tableFourSec.removeSelectedRow();
}
});
}
return panel;
}
 
887,6 → 1061,83
return panel;
}
 
private JPanel createCategorieComptablePanel() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setOpaque(false);
GridBagConstraints c = new DefaultGridBagConstraints();
 
// Ajout catégorie
c.gridwidth = 1;
c.weightx = 0;
c.gridy++;
c.gridx = 0;
panel.add(new JLabel("Ajouter la catégorie "), c);
 
final ElementComboBox boxCat = new ElementComboBox();
boxCat.init(Configuration.getInstance().getDirectory().getElement("CATEGORIE_COMPTABLE"));
 
c.gridx++;
panel.add(boxCat, c);
 
c.fill = GridBagConstraints.NONE;
c.gridx++;
JButton buttonAjouter = new JButton("Ajouter");
buttonAjouter.setOpaque(false);
panel.add(buttonAjouter, c);
c.gridx++;
JButton buttonSupprimer = new JButton("Supprimer");
buttonSupprimer.setOpaque(false);
panel.add(buttonSupprimer, c);
 
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
c.gridy++;
c.gridx = 0;
c.fill = GridBagConstraints.BOTH;
this.tableCatComptable.setOpaque(false);
panel.add(this.tableCatComptable, c);
 
// Listeners
buttonAjouter.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
 
SQLRow rowCat = boxCat.getSelectedRow();
if (rowCat == null || rowCat.isUndefined()) {
return;
}
int nbRows = tableCatComptable.getModel().getRowCount();
 
for (int i = 0; i < nbRows; i++) {
SQLRowValues rowVals = tableCatComptable.getModel().getRowValuesAt(i);
int idTarif = Integer.parseInt(rowVals.getObject("ID_CATEGORIE_COMPTABLE").toString());
if (idTarif == rowCat.getID()) {
JOptionPane.showMessageDialog(null, "Impossible d'ajouter.\nLa catégorie est déjà présente dans la liste!");
return;
}
}
 
SQLRowValues rowVals = new SQLRowValues(Configuration.getInstance().getBase().getTable("ARTICLE_CATEGORIE_COMPTABLE"));
if (getSelectedID() > 1) {
rowVals.put("ID_ARTICLE", getSelectedID());
}
rowVals.put("ID_CATEGORIE_COMPTABLE", rowCat.getID());
tableCatComptable.getModel().addRow(rowVals);
}
});
buttonSupprimer.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tableCatComptable.removeSelectedRow();
}
});
return panel;
}
 
private JPanel createBOMpanel() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setOpaque(false);
997,7 → 1248,7
this.textMarge.getDocument().addDocumentListener(this.listenerMargeTextMarge);
cAchat.gridx++;
cAchat.weightx = 0;
p.add(new JLabel("% "), cAchat);
p.add(this.labelMarge, cAchat);
 
// Poids
JLabel labelPds = new JLabel(getLabelFor("POIDS"));
1026,7 → 1277,58
c.fill = GridBagConstraints.NONE;
 
this.add(p, c);
c.gridx = 0;
c.gridy++;
c.gridwidth = 1;
 
if (getTable().contains("ID_COUT_REVIENT")) {
// Cout de revient
c.weightx = 0;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(new JLabel(getLabelFor("ID_COUT_REVIENT"), SwingConstants.RIGHT), c);
 
JPanel pCR = new JPanel(new GridBagLayout());
GridBagConstraints cCR = new DefaultGridBagConstraints();
cCR.insets = new Insets(0, 0, 0, 4);
this.boxCR = new ElementComboBox(true, 15);
 
pCR.add(boxCR, cCR);
this.addView(boxCR, "ID_COUT_REVIENT");
DefaultGridBagConstraints.lockMinimumSize(boxCR);
boxCR.addModelListener("wantedID", new PropertyChangeListener() {
 
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!isFilling()) {
ReferenceArticleSQLComponent.this.textPVHT.getDocument().removeDocumentListener(ReferenceArticleSQLComponent.this.listenerMargeTextVT);
updateVtFromMarge();
ReferenceArticleSQLComponent.this.textPVHT.getDocument().addDocumentListener(ReferenceArticleSQLComponent.this.listenerMargeTextVT);
}
}
});
cCR.gridx++;
this.boxMargeWithCR = new JCheckBox(getLabelFor("MARGE_WITH_COUT_REVIENT"));
pCR.add(boxMargeWithCR, cCR);
addView(boxMargeWithCR, "MARGE_WITH_COUT_REVIENT");
boxMargeWithCR.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
if (!isFilling()) {
ReferenceArticleSQLComponent.this.textPVHT.getDocument().removeDocumentListener(ReferenceArticleSQLComponent.this.listenerMargeTextVT);
updateVtFromMarge();
ReferenceArticleSQLComponent.this.textPVHT.getDocument().addDocumentListener(ReferenceArticleSQLComponent.this.listenerMargeTextVT);
}
}
});
c.gridx++;
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.WEST;
c.weightx = 1;
c.fill = GridBagConstraints.NONE;
this.add(pCR, c);
}
 
// PV HT
c.gridx = 0;
c.gridy++;
1121,11 → 1423,13
this.taxeListener = new PropertyChangeListener() {
 
public void propertyChange(PropertyChangeEvent evt) {
if (!isFilling()) {
if (ReferenceArticleSQLComponent.this.textPVHT.getText().trim().length() > 0) {
setTextTTC();
} else {
setTextHT();
}
}
tableTarifVente.fireModification();
}
};
1258,8 → 1562,11
 
@Override
public void update() {
SQLRow row = this.getTable().getRow(this.getSelectedID());
super.update();
this.tableTarifVente.updateField("ID_ARTICLE", getSelectedID());
this.tableCatComptable.updateField("ID_ARTICLE", getSelectedID());
this.tableFourSec.updateField("ID_ARTICLE", getSelectedID());
this.tableTarifQteVente.updateField("ID_ARTICLE", getSelectedID());
if (this.tableBom != null) {
this.tableBom.updateField("ID_ARTICLE_PARENT", getSelectedID());
1270,8 → 1577,26
if (this.codeFournisseurTable != null) {
this.codeFournisseurTable.updateField("ID_ARTICLE", getSelectedID());
}
 
((ReferenceArticleSQLElement) getElement()).initStock(getSelectedID());
 
SQLSelect sel = new SQLSelect();
SQLTable tableStock = getTable().getTable("STOCK");
sel.addSelect(tableStock.getKey());
Where w = new Where(tableStock.getField("ID_ARTICLE"), "=", getSelectedID()).and(new Where(tableStock.getField("ID_DEPOT_STOCK"), "=", row.getForeignID("ID_DEPOT_STOCK")));
sel.setWhere(w);
 
List<SQLRow> stock = SQLRowListRSH.execute(sel);
if (stock != null && stock.size() == 1) {
try {
row.createEmptyUpdateRow().put("ID_STOCK", stock.get(0).getID()).update();
} catch (SQLException e) {
ExceptionHandler.handle("Erreur lors de la mise à jour du stock principal", e);
}
}
 
}
 
/**
* Sélection d'un mode de vente pour l'article. Affiche les prix metriques requis et fixe les
* valeurs.
1324,6 → 1649,8
public int insert(SQLRow order) {
int id = super.insert(order);
this.tableTarifVente.updateField("ID_ARTICLE", id);
this.tableCatComptable.updateField("ID_ARTICLE", id);
this.tableFourSec.updateField("ID_ARTICLE", id);
this.tableTarifQteVente.updateField("ID_ARTICLE", id);
if (this.tableBom != null) {
this.tableBom.updateField("ID_ARTICLE_PARENT", id);
1333,6 → 1660,7
if (this.codeFournisseurTable != null) {
this.codeFournisseurTable.updateField("ID_ARTICLE", id);
}
((ReferenceArticleSQLElement) getElement()).initStock(id);
return id;
}
 
1341,12 → 1669,16
SQLRowValues rowVals = new SQLRowValues(getTable());
 
rowVals.put("ID_TAXE", TaxeCache.getCache().getFirstTaxe().getID());
rowVals.put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID);
rowVals.put("ID_UNITE_VENTE", UniteVenteArticleSQLElement.A_LA_PIECE);
rowVals.put("QTE_UNITAIRE", BigDecimal.ONE);
rowVals.put("ID_MODE_VENTE_ARTICLE", ReferenceArticleSQLElement.A_LA_PIECE);
selectModeVente(ReferenceArticleSQLElement.A_LA_PIECE);
rowVals.put("VALEUR_METRIQUE_1", Float.valueOf("1.0"));
rowVals.put("PA_HT", BigDecimal.ZERO);
rowVals.put("QTE_UNITAIRE", BigDecimal.ONE);
rowVals.put("POIDS", Float.valueOf(0));
rowVals.put("GESTION_STOCK", Boolean.TRUE);
 
return rowVals;
}