OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 131 → Rev 132

/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/component/SocieteCommonSQLElement.java
50,7 → 50,7
import org.openconcerto.ui.FormLayouter;
import org.openconcerto.ui.TitledSeparator;
import org.openconcerto.ui.component.InteractionMode;
import org.openconcerto.utils.CollectionMap;
import org.openconcerto.utils.ListMap;
 
/**
* Sociétés existantes avec le nom de la base associée
78,13 → 78,17
return sysRoot.getRoot(rootName);
}
 
public SocieteCommonSQLElement(DBRoot root) {
super(root.getTable(TABLE_NAME), "une société", "sociétés");
}
 
public SocieteCommonSQLElement() {
super(TABLE_NAME, "une société", "sociétés");
this(Configuration.getInstance().getRoot());
}
 
@Override
public CollectionMap<String, String> getShowAs() {
return CollectionMap.singleton(null, getListFields());
public ListMap<String, String> getShowAs() {
return ListMap.singleton(null, getListFields());
}
 
protected List<String> getListFields() {
99,13 → 103,6
return l;
}
 
protected List<String> getPrivateFields() {
final List<String> l = new ArrayList<String>();
l.add("ID_EXERCICE_COMMON");
l.add("ID_ADRESSE_COMMON");
return l;
}
 
public final static Date getDateDebutExercice() {
 
SQLTable tableExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON");
225,6 → 222,20
c.weightx = 1;
this.add(this.textNumAPE, c);
 
// Org social
c.gridy++;
c.gridx = 0;
c.weightx = 0;
JLabel labelIDSoc = new JLabel(getLabelFor("ORG_PROTECTION_SOCIAL_ID"));
labelIDSoc.setHorizontalAlignment(SwingConstants.RIGHT);
this.add(labelIDSoc, c);
 
c.gridx++;
c.weightx = 1;
JTextField fieldIDSoc = new JTextField();
this.add(fieldIDSoc, c);
this.addView(fieldIDSoc, "ORG_PROTECTION_SOCIAL_ID");
 
// RCS
c.gridy++;
c.gridx = 0;
252,6 → 263,33
this.add(fieldCapital, c);
this.addView(fieldCapital, "CAPITAL");
 
// IBAN
c.gridy++;
c.gridx = 0;
c.weightx = 0;
JLabel labelIban = new JLabel(getLabelFor("IBAN"));
labelIban.setHorizontalAlignment(SwingConstants.RIGHT);
this.add(labelIban, c);
 
c.gridx++;
c.weightx = 1;
JTextField fieldIban = new JTextField();
this.add(fieldIban, c);
this.addView(fieldIban, "IBAN");
 
// Capital
c.gridx++;
c.weightx = 0;
JLabel labelBIC = new JLabel(getLabelFor("BIC"));
labelBIC.setHorizontalAlignment(SwingConstants.RIGHT);
this.add(labelBIC, c);
 
c.gridx++;
c.weightx = 1;
JTextField fieldBIC = new JTextField();
this.add(fieldBIC, c);
this.addView(fieldBIC, "BIC");
 
// Assurance
if (getTable().contains("NUMERO_POLICE")) {
c.gridy++;
493,6 → 531,13
}
}
 
@Override
public void update() {
// TODO Auto-generated method stub
super.update();
ComptaPropsConfiguration.getInstanceCompta().getRowSociete().fetchValues();
}
 
public void disableEdition() {
this.combo.setVisible(false);
this.labelPlan.setVisible(false);
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/component/TransfertBaseSQLComponent.java
127,8 → 127,7
return;
}
// remove foreign and replace rowvalues by id
final SQLRowValues singleRowValues = new SQLRowValues(r.asRowValues(), ForeignCopyMode.COPY_ID_OR_RM);
super.select(singleRowValues);
super.select(r);
final RowValuesTable table = this.getRowValuesTable();
if (table != null) {
table.clear();
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/element/PaysSQLElement.java
17,7 → 17,7
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.CollectionMap;
import org.openconcerto.utils.ListMap;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
48,8 → 48,8
}
 
@Override
public CollectionMap<String, String> getShowAs() {
return CollectionMap.singleton(null, getComboFields());
public ListMap<String, String> getShowAs() {
return ListMap.singleton(null, getComboFields());
}
 
/*
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/element/AdresseCommonSQLElement.java
14,8 → 14,11
package org.openconcerto.erp.core.common.element;
 
import org.openconcerto.erp.core.common.component.AdresseCommonSQLComponent;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.ConfSQLElement;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.utils.ListMap;
 
import java.util.ArrayList;
import java.util.List;
22,8 → 25,12
 
public class AdresseCommonSQLElement extends ConfSQLElement {
 
public AdresseCommonSQLElement(DBRoot root) {
super(root.getTable("ADRESSE_COMMON"), "une adresse", "adresses");
}
 
public AdresseCommonSQLElement() {
super("ADRESSE_COMMON", "une adresse", "adresses");
this(Configuration.getInstance().getRoot());
}
 
protected List<String> getListFields() {
40,6 → 47,16
return l;
}
 
@Override
public ListMap<String, String> getShowAs() {
return ListMap.singleton(null, "RUE", "VILLE");
}
 
@Override
public boolean isPrivate() {
return true;
}
 
/*
* (non-Javadoc)
*
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/element/SocieteSQLConfElement.java
New file
0,0 → 1,629
/*
* 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.common.element;
 
import org.openconcerto.erp.config.Gestion;
import org.openconcerto.erp.config.Log;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.PropsConfiguration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.FieldPath;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.SQLTable.VirtualFields;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.request.ListSQLRequest;
import org.openconcerto.sql.request.SQLFieldTranslator;
import org.openconcerto.sql.ui.light.GroupToLightUIConvertor;
import org.openconcerto.sql.ui.light.LightEditFrame;
import org.openconcerto.sql.ui.light.LightUIPanelFiller;
import org.openconcerto.sql.ui.light.SearchInfo;
import org.openconcerto.sql.users.UserManager;
import org.openconcerto.sql.view.EditFrame;
import org.openconcerto.sql.view.EditPanel.EditMode;
import org.openconcerto.sql.view.list.SQLTableModelColumn;
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
import org.openconcerto.ui.AutoHideListener;
import org.openconcerto.ui.group.Group;
import org.openconcerto.ui.light.ColumnSpec;
import org.openconcerto.ui.light.ColumnsSpec;
import org.openconcerto.ui.light.InformationLine;
import org.openconcerto.ui.light.LightUIElement;
import org.openconcerto.ui.light.LightUIFrame;
import org.openconcerto.ui.light.LightUILine;
import org.openconcerto.ui.light.LightUIPanel;
import org.openconcerto.ui.light.LightUITable;
import org.openconcerto.ui.light.Row;
import org.openconcerto.ui.light.RowSelectionSpec;
import org.openconcerto.ui.light.RowsBulk;
import org.openconcerto.ui.light.SearchSpec;
import org.openconcerto.ui.light.SimpleTextLine;
import org.openconcerto.ui.light.TableContent;
import org.openconcerto.ui.light.TableSpec;
import org.openconcerto.ui.table.TableCellRendererUtils;
import org.openconcerto.utils.GestionDevise;
import org.openconcerto.utils.cc.ITransformer;
import org.openconcerto.utils.convertor.ValueConvertor;
 
import java.awt.Color;
import java.awt.Component;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
 
import org.jdom2.Document;
import org.jdom2.input.DOMBuilder;
 
/**
* SQLElement de la base société
*
* @author Administrateur
*
*/
public abstract class SocieteSQLConfElement extends SQLElement {
 
{
this.setL18nLocation(Gestion.class);
}
 
public SocieteSQLConfElement(SQLTable table, String singular, String plural) {
super(singular, plural, table);
}
 
public SocieteSQLConfElement(SQLTable table) {
this(table, null);
}
 
public SocieteSQLConfElement(SQLTable table, String code) {
super(table, null, code);
}
 
public static final TableCellRenderer CURRENCY_RENDERER = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component res = super.getTableCellRendererComponent(table, GestionDevise.currencyToString((BigDecimal) value), isSelected, hasFocus, row, column);
// this renderer can be decorated by e.g. ListeFactureRenderer which does a
// setBackground(), thus always reset the colors
// MAYBE always use ProxyComp as in AlternateTableCellRenderer to leave the decorated
// renderer as found
TableCellRendererUtils.setColors(res, table, isSelected);
((JLabel) res).setHorizontalAlignment(SwingConstants.RIGHT);
return res;
}
};
 
static public final JPanel createAdditionalPanel() {
return AutoHideListener.listen(new JPanel());
}
 
@Override
protected String createCode() {
return createCodeFromPackage();
}
 
public SQLRowValues createDefaultRowValues() {
return new SQLRowValues(getTable());
}
 
public RowsBulk doSearch(final PropsConfiguration configuration, final SearchSpec searchSpec, final ColumnsSpec columnsSpec, final int startIndex, final int limit) {
long t1 = System.currentTimeMillis();
 
final SQLTableModelSourceOnline tableSource = this.getTableSource();
final SearchInfo sInfo = (searchSpec != null) ? new SearchInfo(searchSpec) : null;
 
final ListSQLRequest req = tableSource.getReq();
req.setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
@Override
public SQLSelect transformChecked(final SQLSelect sel) {
setWhere(sel, tableSource, sInfo, startIndex, -1);
return sel;
}
});
 
long t2 = System.currentTimeMillis();
int count = req.getValuesCount();
long t3 = System.currentTimeMillis();
 
req.setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
@Override
public SQLSelect transformChecked(final SQLSelect sel) {
setWhere(sel, tableSource, sInfo, startIndex, limit);
return sel;
}
});
 
// get values
long t4 = System.currentTimeMillis();
final List<SQLRowValues> rowValues = req.getValues();
final int size = rowValues.size();
long t5 = System.currentTimeMillis();
System.err.println("DefaultTableContentHandler.handle() getReq :" + (t2 - t1) + " ms");
System.err.println("DefaultTableContentHandler.handle() getValuesCount() :" + count + " : " + (t3 - t2) + " ms");
System.err.println("DefaultTableContentHandler.handle() setWhere : " + (t4 - t3) + " ms");
System.err.println("DefaultTableContentHandler.handle() getValues() :" + size + " : " + (t5 - t4) + " ms");
 
final List<SQLTableModelColumn> allCols = tableSource.getColumns();
final List<Row> matchingRows = new ArrayList<Row>();
 
// FIXME: Dégager la conf xml si les nombre de colonnes ne match plus
final int columnsCount = allCols.size();
if (columnsSpec.getColumnCount() == columnsCount) {
for (int i = 0; i < size; i++) {
final SQLRowValues rowV = rowValues.get(i);
final Row row = new Row(rowV.getID());
final List<Object> l = new ArrayList<Object>();
for (int j = 0; j < columnsCount; j++) {
final String columnId = columnsSpec.getColumn(j).getId();
final SQLTableModelColumn col = this.getColumnFromId(allCols, columnId);
 
if (col != null) {
Object value = col.show(rowV);
if (col.getLightUIrenderer() != null) {
value = col.getLightUIrenderer().getLightUIElement(value, i, j);
}
if (value instanceof SQLRowValues) {
value = ((SQLRowValues) value).getIDNumber();
}
l.add(value);
} else {
throw new IllegalArgumentException("column " + columnId + " is in xmlPref but it is not found in SQLTableModelColumn");
}
}
row.setValues(l);
matchingRows.add(row);
}
} else {
for (int i = 0; i < size; i++) {
final SQLRowValues rowV = rowValues.get(i);
final Row row = new Row(rowV.getID());
final List<Object> l = new ArrayList<Object>();
for (int j = 0; j < columnsCount; j++) {
final SQLTableModelColumn tableModelColumn = allCols.get(j);
Object value = tableModelColumn.show(rowV);
if (tableModelColumn.getLightUIrenderer() != null) {
value = tableModelColumn.getLightUIrenderer().getLightUIElement(value, i, j);
}
if (value instanceof SQLRowValues) {
value = ((SQLRowValues) value).getIDNumber();
}
 
l.add(value);
}
row.setValues(l);
matchingRows.add(row);
}
}
 
return new RowsBulk(matchingRows, startIndex, count);
}
 
private void setWhere(final SQLSelect sel, final SQLTableModelSourceOnline tableSource, final SearchInfo sInfo, final int startIndex, final int limit) {
if (sInfo != null) {
final List<SQLTableModelColumn> cols = tableSource.getColumns();
final Set<SQLField> fields = new HashSet<SQLField>();
for (final SQLTableModelColumn sqlTableModelColumn : cols) {
fields.addAll(sqlTableModelColumn.getFields());
}
final List<SQLField> strFields = new ArrayList<SQLField>();
final List<Where> wheres = new ArrayList<Where>();
for (final SQLField sqlField : fields) {
if (sqlField.getType().getJavaType().equals(String.class)) {
strFields.add(sqlField);
final List<String> texts = sInfo.getTexts();
for (String string : texts) {
final Where w = new Where(sel.getAlias(sqlField), "LIKE", "%" + string + "%");
wheres.add(w);
}
 
}
}
sel.setWhere(Where.or(wheres));
}
if (limit != -1) {
sel.setLimit(limit);
sel.setOffset(startIndex);
}
}
 
protected String getReadOnlyFrameTitle(final SQLRowValues sqlRow) {
return EditFrame.getReadOnlyMessage(this);
}
 
protected String getModificationFrameTitle(final SQLRowValues sqlRow) {
return EditFrame.getModifyMessage(this);
}
 
protected String getCreationFrameTitle() {
return EditFrame.getCreateMessage(this);
}
 
/**
* Return a code that doesn't change when subclassing to allow to easily change a SQLElement
* while keeping the same code. To achieve that, the code isn't
* {@link #createCodeFromPackage(Class) computed} with <code>this.getClass()</code>. We iterate
* up through our superclass chain, and as soon as we find an abstract class, we stop and use
* the previous class (i.e. non abstract). E.g. any direct subclass of
* {@link ComptaSQLConfElement} will still use <code>this.getClass()</code>, but so is one of
* its subclass.
*
* @return a code computed from the superclass just under the first abstract superclass.
* @see #createCodeFromPackage(Class)
*/
protected final String createCodeFromPackage() {
return createCodeFromPackage(getLastNonAbstractClass());
}
 
private final Class<? extends ComptaSQLConfElement> getLastNonAbstractClass() {
Class<?> prev = null;
Class<?> cl = this.getClass();
// test loop
assert !Modifier.isAbstract(cl.getModifiers()) && ComptaSQLConfElement.class.isAssignableFrom(cl) && Modifier.isAbstract(ComptaSQLConfElement.class.getModifiers());
while (!Modifier.isAbstract(cl.getModifiers())) {
prev = cl;
cl = cl.getSuperclass();
}
assert ComptaSQLConfElement.class.isAssignableFrom(prev);
@SuppressWarnings("unchecked")
final Class<? extends ComptaSQLConfElement> res = (Class<? extends ComptaSQLConfElement>) prev;
return res;
}
 
static protected String createCodeFromPackage(final Class<? extends ComptaSQLConfElement> cl) {
String canonicalName = cl.getName();
if (canonicalName.contains("erp.core") && canonicalName.contains(".element")) {
int i = canonicalName.indexOf("erp.core") + 9;
int j = canonicalName.indexOf(".element");
canonicalName = canonicalName.substring(i, j);
}
return canonicalName;
}
 
@Override
protected void _initTableSource(SQLTableModelSourceOnline res) {
super._initTableSource(res);
for (final SQLTableModelColumn col : res.getColumns()) {
// TODO getDeviseFields()
if (col.getValueClass() == Long.class || col.getValueClass() == BigInteger.class) {
col.setConverter(new ValueConvertor<Number, BigDecimal>() {
@Override
public BigDecimal convert(Number o) {
if (o == null) {
System.err.println("ComptaSQLConfElement._initTableSource: Warning null Number conversion (" + this + ")");
return BigDecimal.ZERO;
}
return new BigDecimal(o.longValue()).movePointLeft(2);
}
 
@Override
public Number unconvert(BigDecimal o) {
 
if (o == null) {
System.err.println("ComptaSQLConfElement._initTableSource: Warning null BigDecimal conversion (" + this + ")");
return 0;
}
return o.movePointRight(2);
}
}, BigDecimal.class);
col.setRenderer(CURRENCY_RENDERER);
}
}
}
 
/**
* Create a new panel which contains the table
*
* @return The LightUIPanel which contains the LightUITable
* @throws IllegalArgumentException
*/
public LightUIPanel createUIPanelForTable(final Configuration configuration) throws IllegalArgumentException {
final LightUIPanel panel = new LightUIPanel(this.getCode());
 
final LightUILine listLine = new LightUILine();
listLine.addChild(createUIElementForTable(configuration));
 
panel.setWeightX(1);
panel.setFillWidth(true);
panel.addChild(listLine);
return panel;
}
 
/**
* Get columns user preferences for a specific table
*
* @param userId - Id of the user who want view the table
* @param tableId - Id of table to show
* @param sqlColumns - List of columns to be displayed
* @return the XML which contains user preferences
*/
protected Document getColumnsUserPerfs(final Configuration configuration, final int userId, final String tableId, final List<SQLTableModelColumn> sqlColumns) {
Document columnsPrefs = null;
try {
final DOMBuilder in = new DOMBuilder();
final org.w3c.dom.Document w3cDoc = configuration.getXMLConf(userId, tableId);
if (w3cDoc != null) {
columnsPrefs = in.build(w3cDoc);
}
} catch (Exception ex) {
throw new IllegalArgumentException("Failed to get ColumnPrefs for table " + tableId + " and for user " + userId + "\n" + ex.getMessage());
}
 
return columnsPrefs;
}
 
/**
* Create ColumnsSpec from list of SQLTableModelColumn and apply user preferences
*
* @param columns - list of SQLTableModelColumn (columns to be displayed)
* @param columnsPrefs - user preferences for table columns
* @return New ColumnsSpec with user preferences application
*/
protected ColumnsSpec createColumnsSpec(final Configuration configuration, final List<SQLTableModelColumn> columns, final Document columnsPrefs) {
final List<String> possibleColumnIds = new ArrayList<String>();
final List<String> sortedIds = new ArrayList<String>();
final List<ColumnSpec> columnsSpec = new ArrayList<ColumnSpec>();
 
final int columnsCount = columns.size();
 
for (int i = 0; i < columnsCount; i++) {
final SQLTableModelColumn sqlColumn = columns.get(i);
// TODO : creer la notion d'ID un peu plus dans le l'esprit sales.invoice.amount
final String columnId = sqlColumn.getIdentifier();
 
possibleColumnIds.add(columnId);
Class<?> valueClass = sqlColumn.getValueClass();
if (sqlColumn.getLightUIrenderer() != null) {
valueClass = LightUIElement.class;
}
 
// FIXME: bad code, if column is composed of more than one SQLField, this code could be
// print a wrong column name
String columnName = "";
if (sqlColumn.getFields().size() == 1) {
final SQLField field = sqlColumn.getFields().iterator().next();
columnName = SQLTableModelColumnPath.getDescFor(field, configuration).getTitleLabel();
}
 
if (columnName == null || columnName.isEmpty()) {
columnName = sqlColumn.getName();
}
/***********************/
 
columnsSpec.add(new ColumnSpec(columnId, valueClass, columnName, null, false, null));
}
// FIXME : recuperer l'info sauvegardée sur le serveur par user (à coder)
sortedIds.add(columnsSpec.get(0).getId());
 
final ColumnsSpec cSpec = new ColumnsSpec(this.getCode(), columnsSpec, possibleColumnIds, sortedIds);
cSpec.setAllowMove(true);
cSpec.setAllowResize(true);
cSpec.setUserPrefs(columnsPrefs);
 
return cSpec;
}
 
/**
* Create the LightUITable associated to this ComptaSQLConfElement
*
* @return The LightUITable associated to this ComptaSQLConfElement
* @throws IllegalArgumentException
*/
public LightUITable createUIElementForTable(final Configuration configuration) throws IllegalArgumentException {
final String tableId = this.getCode() + ".table";
 
final SQLTableModelSourceOnline source = this.getTableSource();
final List<SQLTableModelColumn> columns = source.getColumns();
 
// FIXME: replace UserManager.getUserID() by session.getUser().getId()
final Document columnsPrefs = this.getColumnsUserPerfs(configuration, UserManager.getUserID(), tableId, columns);
final RowSelectionSpec selection = new RowSelectionSpec(tableId);
final ColumnsSpec columnsSpec = this.createColumnsSpec(configuration, columns, columnsPrefs);
final TableSpec tSpec = new TableSpec(tableId, selection, columnsSpec);
 
final LightUITable table = new LightUITable(tableId);
table.setFillWidth(true);
table.setWeightX(1);
table.setElementCode(this.getCode());
 
table.setTableSpec(tSpec);
table.addAction(LightUIElement.ACTION_TYPE_SELECTION, "table.infos");
 
return table;
}
 
/**
* Create buttons from SQLElement secondary row actions
*/
public LightUILine createSecondaryRowActionLine(final RowSelectionSpec selection) {
return null;
}
 
/**
* Create information ui panel for selected lines. By default, all fields in SQLRowValues are
* displayed
*
* @param selection - SQLRowValues attach to selected lines
* @return LightUIPanel
*/
public LightUIPanel createDataPanel(final List<SQLRowValues> selection, Configuration configuration) {
if (selection == null) {
return null;
}
final LightUIPanel panel = new LightUIPanel(this.getCode() + ".data.panel");
panel.setVerticallyScrollable(true);
panel.setWeightX(1);
final SQLFieldTranslator translator = configuration.getTranslator();
 
for (final SQLRowValues row : selection) {
final int rowId = row.getID();
final LightUILine mainLine = new LightUILine();
final LightUIPanel mainLinePanel = new LightUIPanel(panel.getId() + ".main.line." + rowId);
mainLinePanel.setWeightX(1);
mainLinePanel.addChild(new SimpleTextLine("Information sur l'élément n°" + rowId, true, LightUIElement.HALIGN_CENTER));
final LightUILine lineData = new LightUILine();
final LightUIPanel dataPanel = new LightUIPanel(this.getCode() + ".data.panel." + rowId);
dataPanel.setWeightX(1);
for (String fieldName : row.getFields()) {
this.addFieldToPanel(fieldName, dataPanel, row, translator);
}
lineData.addChild(dataPanel);
mainLinePanel.addChild(lineData);
mainLine.addChild(mainLinePanel);
panel.addChild(mainLine);
}
return panel;
}
 
public void addFieldToPanel(final String fieldName, final LightUIPanel dataPanel, final SQLRowValues row, final SQLFieldTranslator translator) {
addFieldToPanel(fieldName, dataPanel, row, translator, false, "");
}
 
static private final VirtualFields FIELDS_TO_IGNORE = VirtualFields.PRIMARY_KEY.union(VirtualFields.ARCHIVE).union(VirtualFields.ORDER);
 
/**
* Add the field name translation and it's value to the information panel
*
* @param fieldName - Field to be translate
* @param dataPanel - Information panel
* @param row - Row which contains data
* @param translator - Field translator
*/
public void addFieldToPanel(final String fieldName, final LightUIPanel dataPanel, final SQLRowValues row, final SQLFieldTranslator translator, boolean addEmpty, String defaultValue) {
final SQLField field = this.getTable().getField(fieldName);
if (!this.getTable().getFields(FIELDS_TO_IGNORE).contains(field)) {
String key = translator.getLabelFor(field);
boolean error = false;
if (key == null) {
error = true;
key = field.getFieldName();
}
 
String value = "";
if (field.isKey()) {
final List<FieldPath> fieldsPath = getListExpander().expand(field);
for (FieldPath fieldPath : fieldsPath) {
final SQLRowValues foreignRow = row.followPath(fieldPath.getPath());
if (foreignRow != null) {
value += foreignRow.getString(fieldPath.getField().getName()) + " ";
}
}
} else {
value = row.getString(fieldName);
}
boolean isDefault = false;
if (value == null || value.isEmpty()) {
isDefault = true;
value = defaultValue;
}
if (!value.isEmpty() || addEmpty) {
final InformationLine line = new InformationLine(key, value);
if (error) {
line.setLabelColor(Color.RED);
}
line.setItalicOnValue(isDefault);
dataPanel.addChild(line);
}
}
}
 
public Group getEditGroup(final EditMode editMode) {
if (editMode.equals(EditMode.CREATION)) {
return this.getGroupForCreation();
} else {
return this.getGroupForModification();
}
}
 
public GroupToLightUIConvertor getGroupToLightUIConvertor(final PropsConfiguration configuration, final EditMode editMode, final SQLRowValues sqlRow, final long userId) {
final GroupToLightUIConvertor convertor = new GroupToLightUIConvertor(configuration);
if (editMode.equals(EditMode.CREATION)) {
convertor.putAllCustomEditorProvider(this.getCustomEditorProviderForCreation(configuration, userId));
} else {
convertor.putAllCustomEditorProvider(this.getCustomEditorProviderForModification(configuration, sqlRow, userId));
}
convertor.addAllModifer(this.getConvertorModifiers());
 
return convertor;
}
 
/**
* Create the edition frame for this SQLElement
*
* @param configuration current configuration
* @param parentFrame parent frame of the edit frame
* @param editMode edition mode (CREATION, MODIFICATION, READONLY)
* @param sqlRow SQLRowValues use for fill the edition frame
* @param userId ID of current user
* @return the edition frame of this SQLElement
*/
public LightEditFrame createEditFrame(final PropsConfiguration configuration, final LightUIFrame parentFrame, final EditMode editMode, final SQLRowValues sqlRow, final long userId) {
final Group editGroup = this.getEditGroup(editMode);
if (editGroup == null) {
Log.get().severe("The edit group is null for this element : " + this);
return null;
}
 
final GroupToLightUIConvertor convertor = this.getGroupToLightUIConvertor(configuration, editMode, sqlRow, userId);
final LightEditFrame editFrame = convertor.convert(editGroup, sqlRow, parentFrame, editMode);
if (editMode.equals(EditMode.CREATION)) {
editFrame.setTitle(this.getCreationFrameTitle());
} else if (editMode.equals(EditMode.MODIFICATION)) {
editFrame.setTitle(this.getModificationFrameTitle(sqlRow));
new LightUIPanelFiller(editFrame.getFirstChild(LightUIPanel.class)).fillFromRow(configuration, sqlRow);
} else if (editMode.equals(EditMode.READONLY)) {
editFrame.setTitle(this.getReadOnlyFrameTitle(sqlRow));
new LightUIPanelFiller(editFrame.getFirstChild(LightUIPanel.class)).fillFromRow(configuration, sqlRow);
}
 
return editFrame;
}
 
public List<SQLRowValues> getRowValues(final String fieldName, final long id) {
final SQLTableModelSourceOnline tableSource = this.getTableSource(true);
 
final ListSQLRequest req = tableSource.getReq();
req.setWhere(new Where(this.getTable().getField(fieldName), "=", id));
return req.getValues();
}
 
public TableContent createTableContent(final LightUITable uiTable, final String fieldName, final long id) {
final SQLTableModelSourceOnline tableSource = this.getTableSource(true);
final List<SQLTableModelColumn> allCols = tableSource.getColumns();
 
final List<SQLRowValues> listRowValues = this.getRowValues(fieldName, id);
final List<Row> matchingRows = new ArrayList<Row>();
final int size = listRowValues.size();
for (int i = 0; i < size; i++) {
final SQLRowValues rowV = listRowValues.get(i);
matchingRows.add(this.createRowFromSQLRow(rowV, allCols, uiTable.getTableSpec().getColumns()));
}
 
final TableContent tableContent = new TableContent(uiTable.getId(), matchingRows);
 
return tableContent;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/element/AdresseSQLElement.java
55,4 → 55,9
protected String createCode() {
return "address";
}
 
@Override
public boolean isPrivate() {
return true;
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/element/ComptaSQLConfElement.java
13,61 → 13,10
package org.openconcerto.erp.core.common.element;
 
import java.awt.Component;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
 
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.DOMBuilder;
 
import org.openconcerto.erp.config.Gestion;
import org.openconcerto.erp.config.Log;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.PropsConfiguration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.model.FieldPath;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.request.SQLFieldTranslator;
import org.openconcerto.sql.ui.light.GroupToLightUIConvertor;
import org.openconcerto.sql.users.UserManager;
import org.openconcerto.sql.view.list.IListeAction;
import org.openconcerto.sql.view.list.RowAction;
import org.openconcerto.sql.view.list.SQLTableModelColumn;
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
import org.openconcerto.ui.AutoHideListener;
import org.openconcerto.ui.group.Group;
import org.openconcerto.ui.light.ColumnSpec;
import org.openconcerto.ui.light.ColumnsSpec;
import org.openconcerto.ui.light.InformationLine;
import org.openconcerto.ui.light.LightUIButtonWithSelectionContext;
import org.openconcerto.ui.light.LightUIElement;
import org.openconcerto.ui.light.LightUIFrame;
import org.openconcerto.ui.light.LightUILine;
import org.openconcerto.ui.light.LightUIPanel;
import org.openconcerto.ui.light.LightUITable;
import org.openconcerto.ui.light.RowSelectionSpec;
import org.openconcerto.ui.light.SimpleTextLine;
import org.openconcerto.ui.light.TableSpec;
import org.openconcerto.ui.table.TableCellRendererUtils;
import org.openconcerto.utils.GestionDevise;
import org.openconcerto.utils.convertor.ValueConvertor;
import org.openconcerto.utils.i18n.TranslationManager;
 
/**
* SQLElement de la base société
75,28 → 24,10
* @author Administrateur
*
*/
public abstract class ComptaSQLConfElement extends SQLElement {
public abstract class ComptaSQLConfElement extends SocieteSQLConfElement {
 
private static DBRoot baseSociete;
public static final TableCellRenderer CURRENCY_RENDERER = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component res = super.getTableCellRendererComponent(table, GestionDevise.currencyToString((BigDecimal) value), isSelected, hasFocus, row, column);
// this renderer can be decorated by e.g. ListeFactureRenderer which does a
// setBackground(), thus always reset the colors
// MAYBE always use ProxyComp as in AlternateTableCellRenderer to leave the decorated
// renderer as found
TableCellRendererUtils.setColors(res, table, isSelected);
((JLabel) res).setHorizontalAlignment(SwingConstants.RIGHT);
return res;
}
};
 
static public final JPanel createAdditionalPanel() {
return AutoHideListener.listen(new JPanel());
}
 
private static DBRoot getBaseSociete() {
if (baseSociete == null)
baseSociete = ((ComptaBasePropsConfiguration) Configuration.getInstance()).getRootSociete();
103,336 → 34,20
return baseSociete;
}
 
private Group groupForCreation;
private Group groupForModification;
 
{
this.setL18nLocation(Gestion.class);
}
 
public ComptaSQLConfElement(String tableName, String singular, String plural) {
super(singular, plural, getBaseSociete().findTable(tableName, true));
super(getBaseSociete().findTable(tableName, true), singular, plural);
}
 
public ComptaSQLConfElement(String tableName) {
this(tableName, null);
super(getBaseSociete().findTable(tableName, true), null);
}
 
public ComptaSQLConfElement(String tableName, String code) {
super(getBaseSociete().findTable(tableName, true), null, code);
super(getBaseSociete().findTable(tableName, true), code);
}
 
@Override
protected String createCode() {
return createCodeFromPackage();
}
 
/**
* Return a code that doesn't change when subclassing to allow to easily change a SQLElement
* while keeping the same code. To achieve that, the code isn't
* {@link #createCodeFromPackage(Class) computed} with <code>this.getClass()</code>. We iterate
* up through our superclass chain, and as soon as we find an abstract class, we stop and use
* the previous class (i.e. non abstract). E.g. any direct subclass of
* {@link ComptaSQLConfElement} will still use <code>this.getClass()</code>, but so is one of
* its subclass.
*
* @return a code computed from the superclass just under the first abstract superclass.
* @see #createCodeFromPackage(Class)
*/
protected final String createCodeFromPackage() {
return createCodeFromPackage(getLastNonAbstractClass());
}
 
private final Class<? extends ComptaSQLConfElement> getLastNonAbstractClass() {
Class<?> prev = null;
Class<?> cl = this.getClass();
// test loop
assert !Modifier.isAbstract(cl.getModifiers()) && ComptaSQLConfElement.class.isAssignableFrom(cl) && Modifier.isAbstract(ComptaSQLConfElement.class.getModifiers());
while (!Modifier.isAbstract(cl.getModifiers())) {
prev = cl;
cl = cl.getSuperclass();
}
assert ComptaSQLConfElement.class.isAssignableFrom(prev);
@SuppressWarnings("unchecked")
final Class<? extends ComptaSQLConfElement> res = (Class<? extends ComptaSQLConfElement>) prev;
return res;
}
 
static protected String createCodeFromPackage(final Class<? extends ComptaSQLConfElement> cl) {
String canonicalName = cl.getName();
if (canonicalName.contains("erp.core") && canonicalName.contains(".element")) {
int i = canonicalName.indexOf("erp.core") + 9;
int j = canonicalName.indexOf(".element");
canonicalName = canonicalName.substring(i, j);
}
return canonicalName;
}
 
@Override
protected void _initTableSource(SQLTableModelSourceOnline res) {
super._initTableSource(res);
for (final SQLTableModelColumn col : res.getColumns()) {
// TODO getDeviseFields()
if (col.getValueClass() == Long.class || col.getValueClass() == BigInteger.class) {
col.setConverter(new ValueConvertor<Number, BigDecimal>() {
@Override
public BigDecimal convert(Number o) {
if (o == null) {
System.err.println("ComptaSQLConfElement._initTableSource: Warning null Number conversion (" + this + ")");
return BigDecimal.ZERO;
}
return new BigDecimal(o.longValue()).movePointLeft(2);
}
 
@Override
public Number unconvert(BigDecimal o) {
 
if (o == null) {
System.err.println("ComptaSQLConfElement._initTableSource: Warning null BigDecimal conversion (" + this + ")");
return 0;
}
return o.movePointRight(2);
}
}, BigDecimal.class);
col.setRenderer(CURRENCY_RENDERER);
}
}
}
 
/**
* Create a new panel which contains the table
* @return The LightUIPanel which contains the LightUITable
* @throws IllegalArgumentException
*/
public LightUIPanel createUIPanelForTable() throws IllegalArgumentException {
final LightUILine listLine = new LightUILine();
listLine.add(createUIElementForTable());
 
final LightUIPanel panel = new LightUIPanel(this.getCode());
panel.addLine(listLine);
return panel;
}
/**
* Get columns user preferences for a specific table
* @param userId - Id of the user who want view the table
* @param tableId - Id of table to show
* @param sqlColumns - List of columns to be displayed
* @return the XML which contains user preferences
*/
protected Document getColumnsUserPerfs(final int userId, final String tableId, final List<SQLTableModelColumn> sqlColumns) {
Document columnsPrefs = null;
try {
final DOMBuilder in = new DOMBuilder();
final org.w3c.dom.Document w3cDoc = Configuration.getInstance().getXMLConf(userId, tableId);
if (w3cDoc != null) {
columnsPrefs = in.build(w3cDoc);
}
} catch (Exception ex) {
throw new IllegalArgumentException("Failed to get ColumnPrefs for table " + tableId + " and for user " + userId + "\n" + ex.getMessage());
}
if (columnsPrefs != null) {
final Element rootElement = columnsPrefs.getRootElement();
if (!rootElement.getName().equals("list")) {
throw new IllegalArgumentException("invalid xml, roots node list expected but " + rootElement.getName() + " found");
}
 
final int columnsCount = sqlColumns.size();
final List<Element> xmlColumns = rootElement.getChildren();
if (xmlColumns.size() != columnsCount) {
columnsPrefs = null;
}
}
return columnsPrefs;
}
/**
* Create ColumnsSpec from list of SQLTableModelColumn and apply user preferences
* @param columns - list of SQLTableModelColumn (columns to be displayed)
* @param columnsPrefs - user preferences for table columns
* @return New ColumnsSpec with user preferences application
*/
protected ColumnsSpec createColumnsSpec(final List<SQLTableModelColumn> columns, final Document columnsPrefs) {
final List<String> possibleColumnIds = new ArrayList<String>();
final List<String> sortedIds = new ArrayList<String>();
final List<ColumnSpec> columnsSpec = new ArrayList<ColumnSpec>();
final int columnsCount = columns.size();
for(int i = 0; i < columnsCount; i++) {
final SQLTableModelColumn sqlColumn = columns.get(i);
// TODO : creer la notion d'ID un peu plus dans le l'esprit sales.invoice.amount
final String columnId = sqlColumn.getIdentifier();
possibleColumnIds.add(columnId);
columnsSpec.add(new ColumnSpec(columnId, sqlColumn.getValueClass(), sqlColumn.getName(), null, false, null));
}
// FIXME : recuperer l'info sauvegardée sur le serveur par user (à coder)
sortedIds.add(columnsSpec.get(0).getId());
final ColumnsSpec cSpec = new ColumnsSpec(this.getCode(), columnsSpec, possibleColumnIds, sortedIds);
cSpec.setAllowMove(true);
cSpec.setAllowResize(true);
cSpec.setUserPrefs(columnsPrefs);
return cSpec;
}
 
/**
* Create the LightUITable associated to this ComptaSQLConfElement
* @return The LightUITable associated to this ComptaSQLConfElement
* @throws IllegalArgumentException
*/
public LightUITable createUIElementForTable() throws IllegalArgumentException {
final String tableId = this.getCode() + ".table";
final SQLTableModelSourceOnline source = this.getTableSource();
final List<SQLTableModelColumn> columns = source.getColumns();
Document columnsPrefs = this.getColumnsUserPerfs(UserManager.getUserID(), tableId, columns);
final RowSelectionSpec selection = new RowSelectionSpec(tableId);
final ColumnsSpec columnsSpec = this.createColumnsSpec(columns, columnsPrefs);
final TableSpec tSpec = new TableSpec(tableId, selection, columnsSpec);
final LightUITable table = new LightUITable(tableId);
table.setVerticallyScrollable(true);
table.setTableSpec(tSpec);
table.addAction(LightUIElement.ACTION_TYPE_SELECTION, "table.infos");
 
return table;
}
 
/**
* Create buttons from SQLElement row actions
* @param selection - user selection
* @return ui line with all available buttons
*/
public LightUILine createRowAction(final RowSelectionSpec selection) {
final LightUILine actionLine = new LightUILine();
final Collection<IListeAction> actions = this.getRowActions();
 
actionLine.setGridAlignment(LightUILine.ALIGN_LEFT);
for (final Iterator<?> iterator = actions.iterator(); iterator.hasNext();) {
final RowAction iListeAction = (RowAction) iterator.next();
if (iListeAction.inHeader()) {
 
final LightUIElement button = new LightUIButtonWithSelectionContext(iListeAction.getID(), iListeAction.getID(), selection.getTableId());
button.setType(LightUIElement.TYPE_BUTTON_WITH_SELECTION_CONTEXT);
 
final String label = TranslationManager.getInstance().getTranslationForAction(iListeAction.getID());
button.setLabel(label);
 
actionLine.add(button);
// TODO: implement
// desc.addControler(new ActivationOnSelectionControler("sales.quote.list",
// element2.getId()));
}
}
return actionLine;
}
 
/**
* Create information ui line for selected lines. By default, all fields in SQLRowValues are displayed
* @param selection - SQLRowValues attach to selected lines
* @return ui
*/
public LightUILine createDataLine(final List<SQLRowValues> selection) {
if (selection == null) {
return null;
}
final LightUILine dataLine = new LightUILine();
final LightUIPanel panel = new LightUIPanel(this.getCode() + ".data.panel");
final SQLFieldTranslator translator = Configuration.getTranslator(this.getTable());
 
for (final SQLRowValues row : selection) {
final int rowId = row.getID();
final LightUILine mainLine = new LightUILine();
final LightUIPanel mainLinePanel = new LightUIPanel(panel.getId() + ".main.line." + rowId);
mainLinePanel.addLine(new SimpleTextLine(mainLinePanel.getId() + ".title", "Information sur l'élément n°" + rowId, true, LightUIElement.HALIGN_CENTER));
final LightUILine lineData = new LightUILine();
final LightUIPanel dataPanel = new LightUIPanel(this.getCode() + ".data.panel." + rowId);
dataPanel.setPanelType(LightUIPanel.TYPE_TABLE);
for (String fieldName : row.getFields()) {
this.addFieldToPanel(fieldName, dataPanel, row, translator);
}
lineData.add(dataPanel);
mainLinePanel.addLine(lineData);
mainLine.add(mainLinePanel);
panel.addLine(mainLine);
}
dataLine.add(panel);
return dataLine;
}
 
/**
* Add the field name translation and it's value to the infomation panel
* @param fieldName - Field to be translate
* @param dataPanel - Information panel
* @param row - Row which contains data
* @param translator - Field translator
*/
public void addFieldToPanel(final String fieldName, final LightUIPanel dataPanel, final SQLRowValues row, final SQLFieldTranslator translator) {
if (!fieldName.equals("ID") && !fieldName.equals("ARCHIVE") && !fieldName.equals("ORDRE")) {
final SQLField field = this.getTable().getField(fieldName);
final String key = translator.getLabelFor(field);
if (key != null) {
String value = "";
if (field.isKey()) {
final List<FieldPath> fieldsPath = Configuration.getInstance().getShowAs().expand(field);
for (FieldPath fieldPath : fieldsPath) {
final SQLRowValues foreignRow = row.followPath(fieldPath.getPath());
if (foreignRow != null) {
value += foreignRow.getString(fieldPath.getField().getName()) + " ";
}
}
} else {
value = row.getString(fieldName);
}
 
if (value != null && !value.equals("")) {
dataPanel.addLine(new InformationLine(dataPanel.getId(), key, value));
}
}
}
}
 
public LightUIFrame createUIFrameForCreation(final PropsConfiguration configuration, final long userId) {
final GroupToLightUIConvertor convertor = new GroupToLightUIConvertor(configuration);
final Group group = getGroupForCreation();
if (group == null) {
Log.get().severe("The group for creation is null for this element : " + this);
return null;
}
final LightUIFrame frame = convertor.convert(group);
return frame;
}
 
public LightUIFrame createUIFrameForModification(final PropsConfiguration configuration, long id, final long userId) {
final GroupToLightUIConvertor convertor = new GroupToLightUIConvertor(configuration);
final Group group = getGroupForModification();
if (group == null) {
Log.get().severe("The group for modification is null for this element : " + this);
return null;
}
final LightUIFrame frame = convertor.convert(getGroupForModification());
return frame;
}
 
public Group getGroupForCreation() {
if (this.groupForCreation != null) {
return this.groupForCreation;
}
return getDefaultGroup();
}
 
public Group getGroupForModification() {
if (this.groupForModification != null) {
return this.groupForModification;
}
return getDefaultGroup();
}
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/FastPrintAskFrame.java
File deleted
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/AbstractVenteArticleItemTable.java
18,6 → 18,8
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
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.TypePrice;
import org.openconcerto.erp.core.sales.product.ui.ArticleRowValuesRenderer;
import org.openconcerto.erp.core.sales.product.ui.CurrencyWithSymbolRenderer;
import org.openconcerto.erp.core.sales.product.ui.QteMultipleRowValuesRenderer;
55,6 → 57,7
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.StringUtils;
import org.openconcerto.utils.Tuple3;
import org.openconcerto.utils.cc.ITransformer;
import org.openconcerto.utils.i18n.TranslationManager;
 
import java.awt.Component;
109,11 → 112,10
super(buttons);
}
 
protected boolean isCellNiveauEditable(SQLRowValues vals) {
protected boolean isCellNiveauEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
RowValuesTableModel model = getModel();
int index = model.row2index(vals);
int niveau = vals.getInt("NIVEAU");
return index + 1 == model.getRowCount() || niveau >= model.getRowValuesAt(index + 1).getInt("NIVEAU");
return rowIndex + 1 == model.getRowCount() || niveau >= model.getRowValuesAt(rowIndex + 1).getInt("NIVEAU");
}
 
SQLTableElement tableElementFacturable;
310,7 → 312,7
// Valeur des métriques
final SQLTableElement tableElement_ValeurMetrique2 = new SQLTableElement(e.getTable().getField("VALEUR_METRIQUE_2"), Float.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
Number modeNumber = (Number) vals.getObject("ID_MODE_VENTE_ARTICLE");
// int mode = vals.getInt("ID_MODE_VENTE_ARTICLE");
if (modeNumber != null && (modeNumber.intValue() == ReferenceArticleSQLElement.A_LA_PIECE || modeNumber.intValue() == ReferenceArticleSQLElement.AU_POID_METRECARRE
317,7 → 319,7
|| modeNumber.intValue() == ReferenceArticleSQLElement.AU_METRE_LONGUEUR)) {
return false;
} else {
return super.isCellEditable(vals);
return super.isCellEditable(vals, rowIndex, columnIndex);
}
}
 
330,13 → 332,13
list.add(tableElement_ValeurMetrique2);
final SQLTableElement tableElement_ValeurMetrique3 = new SQLTableElement(e.getTable().getField("VALEUR_METRIQUE_3"), Float.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
 
Number modeNumber = (Number) vals.getObject("ID_MODE_VENTE_ARTICLE");
if (modeNumber != null && (!(modeNumber.intValue() == ReferenceArticleSQLElement.AU_POID_METRECARRE))) {
return false;
} else {
return super.isCellEditable(vals);
return super.isCellEditable(vals, rowIndex, columnIndex);
}
}
 
349,7 → 351,7
list.add(tableElement_ValeurMetrique3);
final SQLTableElement tableElement_ValeurMetrique1 = new SQLTableElement(e.getTable().getField("VALEUR_METRIQUE_1"), Float.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
 
Number modeNumber = (Number) vals.getObject("ID_MODE_VENTE_ARTICLE");
if (modeNumber != null && (modeNumber.intValue() == ReferenceArticleSQLElement.A_LA_PIECE || modeNumber.intValue() == ReferenceArticleSQLElement.AU_POID_METRECARRE
356,7 → 358,7
|| modeNumber.intValue() == ReferenceArticleSQLElement.AU_METRE_LARGEUR)) {
return false;
} else {
return super.isCellEditable(vals);
return super.isCellEditable(vals, rowIndex, columnIndex);
}
}
 
377,8 → 379,8
}
 
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
 
};
393,8 → 395,8
}
 
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
 
};
411,9 → 413,14
// Prix vente devise
eltUnitDevise = new SQLTableElement(e.getTable().getField("PV_U_DEVISE"), BigDecimal.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return editVTPrice && isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return editVTPrice && isCellNiveauEditable(vals, rowIndex, columnIndex);
}
 
protected Object getDefaultNullValue() {
return BigDecimal.ZERO;
}
 
};
Path p = new Path(getSQLElement().getTable()).addForeignField("ID_DEVISE");
eltUnitDevise.setRenderer(new CurrencyWithSymbolRenderer(new FieldPath(p, "CODE")));
426,8 → 433,8
 
final SQLTableElement tableElement_PrixMetrique1_VenteHT = new SQLTableElement(field, BigDecimal.class, editorPVHT) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return editVTPrice && isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return editVTPrice && isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
tableElement_PrixMetrique1_VenteHT.setRenderer(new CurrencyWithSymbolRenderer());
437,13 → 444,13
 
SQLTableElement qteU = new SQLTableElement(e.getTable().getField("QTE_UNITAIRE"), BigDecimal.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
 
SQLRowAccessor row = vals.getForeign("ID_UNITE_VENTE");
if (row != null && !row.isUndefined() && row.getBoolean("A_LA_PIECE")) {
return false;
} else {
return super.isCellEditable(vals);
return super.isCellEditable(vals, rowIndex, columnIndex);
}
}
 
478,6 → 485,10
this.qte.setPreferredSize(20);
list.add(this.qte);
 
if (e.getTable().contains("RETOUR_STOCK")) {
list.add(new SQLTableElement(e.getTable().getField("RETOUR_STOCK")));
}
 
// Mode de vente
final SQLTableElement tableElement_ModeVente = new SQLTableElement(e.getTable().getField("ID_MODE_VENTE_ARTICLE"));
list.add(tableElement_ModeVente);
492,14 → 503,14
}
 
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
this.ha = new SQLTableElement(prixAchatHTField, BigDecimal.class, editorPAchatHT) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
this.ha.setRenderer(new CurrencyWithSymbolRenderer());
511,8 → 522,8
final DeviseNumericCellEditor editorPVenteHT = new DeviseNumericCellEditor(prixAchatHTField);
final SQLTableElement tableElement_PrixVente_HT = new SQLTableElement(prixVenteHTField, BigDecimal.class, editorPVenteHT) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return editVTPrice && isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return editVTPrice && isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
tableElement_PrixVente_HT.setRenderer(new CurrencyWithSymbolRenderer());
597,8 → 608,8
 
this.totalHT = new SQLTableElement(e.getTable().getField("T_PV_HT"), BigDecimal.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
this.totalHT.setRenderer(new CurrencyWithSymbolRenderer());
631,7 → 642,7
BigDecimal percent = rowVals.getBigDecimal("POURCENT_FACTURABLE");
BigDecimal amount = rowVals.getBigDecimal("MONTANT_FACTURABLE");
Acompte a = new Acompte(percent, amount);
label.setText(a.toString());
label.setText(a.toPlainString(true));
return label;
}
});
665,7 → 676,7
BigDecimal percent = rowVals.getBigDecimal("POURCENT_REMISE");
BigDecimal amount = rowVals.getBigDecimal("MONTANT_REMISE");
Remise a = new Remise(percent, amount);
label.setText(a.toPlainString());
label.setText(a.toPlainString(true));
return label;
}
});
693,8 → 704,8
// Total HT
this.tableElementTotalDevise = new SQLTableElement(e.getTable().getField("PV_T_DEVISE"), BigDecimal.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
Path p = new Path(getSQLElement().getTable()).addForeignField("ID_DEVISE");
711,8 → 722,8
}
 
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
 
};
783,8 → 794,8
// if value not changed
this.tableElementTotalTTC = new SQLTableElement(e.getTable().getField("T_PV_TTC"), BigDecimal.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
return isCellNiveauEditable(vals);
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
return isCellNiveauEditable(vals, rowIndex, columnIndex);
}
};
this.tableElementTotalTTC.setRenderer(new CurrencyWithSymbolRenderer());
809,9 → 820,9
// Autocompletion
final SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
List<String> completionField = new ArrayList<String>();
// completionField.add("POURCENT_REMISE");
 
if (DefaultNXProps.getInstance().getBooleanValue(ARTICLE_SHOW_DEVISE, false)) {
completionField.add("POURCENT_REMISE");
 
completionField.add("CODE_DOUANIER");
}
865,9 → 876,29
for (String string : completionField) {
m.fill(string, string);
}
final Where w = new Where(sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
m.setWhere(w);
 
ITransformer<SQLSelect, SQLSelect> selTrans = new ITransformer<SQLSelect, SQLSelect>() {
@Override
public SQLSelect transformChecked(SQLSelect input) {
 
final SQLTable tableStock = sqlTableArticle.getTable("STOCK");
input.andWhere(new Where(tableStock.getKey(), "=", sqlTableArticle.getField("ID_STOCK")));
input.setExcludeUndefined(false, tableStock);
Where w = new Where(sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE).or(new Where(input.getAlias(tableStock.getKey()), "=", tableStock.getUndefinedID()))
.or(new Where(input.getAlias(tableStock.getField("QTE_REEL")), ">", 0));
 
if (input.getWhere() != null) {
input.setWhere(input.getWhere().and(w));
} else {
input.setWhere(w);
}
input.asString();
return input;
}
};
 
m.setSelectTransformer(selTrans);
 
this.table.setDropTarget(new DropTarget() {
@Override
public synchronized void drop(DropTargetDropEvent dtde) {
876,9 → 907,23
}
});
 
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.CAN_EXPAND_NOMENCLATURE_VT, true)) {
 
table.addMouseListener(new MouseAdapter() {
 
@Override
public void mousePressed(MouseEvent e) {
 
handlePopup(e);
}
 
@Override
public void mouseReleased(MouseEvent e) {
 
handlePopup(e);
}
 
public void handlePopup(MouseEvent e) {
final int rowindex = table.getSelectedRow();
if (rowindex < 0)
return;
902,7 → 947,7
}
}
});
 
}
final AutoCompletionManager m2 = new AutoCompletionManager(tableElementNom, sqlTableArticle.getField("NOM"), this.table, this.table.getRowValuesTableModel()) {
@Override
protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
921,7 → 966,7
m2.fill(string, string);
}
 
m2.setWhere(w);
m2.setSelectTransformer(selTrans);
 
final AutoCompletionManager m3 = new AutoCompletionManager(tableElementArticle, sqlTableArticle.getField("NOM"), this.table, this.table.getRowValuesTableModel(),
ITextWithCompletion.MODE_CONTAINS, true, true, new ValidStateChecker()) {
942,7 → 987,7
m3.fill(string, string);
}
 
m3.setWhere(w);
m3.setSelectTransformer(selTrans);
 
// Deselection de l'article si le code est modifié
tableFamille.addModificationListener(tableElementArticle);
953,11 → 998,11
try {
if (filterFamilleArticle) {
if (row.isForeignEmpty("ID_FAMILLE_ARTICLE")) {
m.setWhere(w);
m2.setWhere(w);
m.setWhere(null);
m2.setWhere(null);
} else {
m.setWhere(w.and(new Where(sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", row.getForeignID("ID_FAMILLE_ARTICLE"))));
m2.setWhere(w.and(new Where(sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", row.getForeignID("ID_FAMILLE_ARTICLE"))));
m.setWhere(new Where(sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", row.getForeignID("ID_FAMILLE_ARTICLE")));
m2.setWhere(new Where(sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", row.getForeignID("ID_FAMILLE_ARTICLE")));
}
}
SQLRowAccessor foreign = row.getForeign("ID_ARTICLE");
1188,7 → 1233,7
 
if (eltUnitDevise != null) {
tableElement_PrixMetrique1_VenteHT.addModificationListener(eltUnitDevise);
 
eltDevise.addModificationListener(eltUnitDevise);
eltUnitDevise.setModifier(new CellDynamicModifier() {
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
if (source != null && source.getField().getName().equals("PV_U_DEVISE")) {
1339,8 → 1384,15
 
if (row != null && !row.isUndefined() && getSQLElement().getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")
&& (field.equalsIgnoreCase("PRIX_METRIQUE_HA_1") || field.equalsIgnoreCase("PA_HT"))) {
 
final BigDecimal prc;
if (row.getBoolean("AUTO_PRIX_REVIENT_NOMENCLATURE")) {
ProductHelper helper = new ProductHelper(row.getTable().getDBRoot());
prc = helper.getBomPriceForQuantity(1, row.getReferentRows(row.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT")), TypePrice.ARTICLE_PRIX_REVIENT);
} else {
ProductComponent productComp = new ProductComponent(row, BigDecimal.ONE);
BigDecimal prc = productComp.getPRC(new Date());
prc = productComp.getPRC(new Date());
}
if (prc == null) {
return BigDecimal.ZERO;
}
1380,7 → 1432,7
return getTarif().getObject("ID_DEVISE");
} else if ((field.equalsIgnoreCase("PV_U_DEVISE"))) {
 
return row.getBigDecimal("PRIX_METRIQUE_VT_1");
return getQtyTarifPvM1(rowDest, fromCompletion);
}
}
if ((field.equalsIgnoreCase("ID_TAXE"))) {
1474,6 → 1526,15
// }
 
SQLRowAccessor rowA = row.getForeign("ID_ARTICLE");
if (rowA != null && !rowA.isUndefined() && rowA.getTable().contains("AUTO_PRIX_MIN_VENTE_NOMENCLATURE") && rowA.getBoolean("AUTO_PRIX_MIN_VENTE_NOMENCLATURE")) {
BigDecimal b = row.getBigDecimal("QTE_UNITAIRE");
int q = row.getInt("QTE");
BigDecimal qteTotal = b.multiply(new BigDecimal(q), DecimalUtils.HIGH_PRECISION);
ProductHelper helper = new ProductHelper(rowA.getTable().getDBRoot());
 
return helper.getBomPriceForQuantity(qteTotal.setScale(0, RoundingMode.HALF_UP).intValue(), rowA.getReferentRows(rowA.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT")),
TypePrice.ARTICLE_PRIX_PUBLIC);
}
BigDecimal result = null;
// BigDecimal remise = null;
if (rowA != null && !rowA.isUndefined() && rowA.getTable().getDBRoot().contains("ARTICLE_PRIX_PUBLIC")) {
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/TotalPanel.java
532,7 → 532,7
}
}
}
rowValsPort.putRowValues("ID_ARTICLE").put("ID_COMPTE_PCE", rowDefaultCptPort);
rowValsPort.putRowValues("ID_ARTICLE").put("ID_COMPTE_PCE", rowDefaultCptPort.getID());
} else {
rowValsPort = null;
}
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/SQLJavaEditor.java
42,6 → 42,8
import javax.swing.JComponent;
import javax.swing.event.DocumentEvent;
 
import org.jgrapht.alg.DijkstraShortestPath;
 
import koala.dynamicjava.interpreter.Interpreter;
import koala.dynamicjava.interpreter.InterpreterException;
import koala.dynamicjava.interpreter.TreeInterpreter;
187,7 → 189,11
Set<SQLRow> set = rowSal.getForeignRows();
for (SQLRow row : set) {
mapCacheRow.put(row.getTable().getName(), row);
Set<SQLRow> set2 = row.getForeignRows();
for (SQLRow row2 : set2) {
mapCacheRow.put(row2.getTable().getName(), row2);
}
}
// System.err.println("LOAD Variable");
for (final Object o : this.mVar) {
// Les SQLFields sont des fields des tables étrangères de la table salarié
199,9 → 205,9
SQLRow rowAssoc = mapCacheRow.get(field.getTable().getName());
 
// on recupere la row associee exemple : SALARIE.INFOS_SALARIE_PAYE
final Set<SQLRow> foreignRows = null;
Set<SQLRow> foreignRows = null;
if (rowAssoc == null) {
rowSal.getForeignRows(field.getTable().getName());
foreignRows = rowSal.getForeignRows(field.getTable().getName());
}
 
if (rowAssoc != null || ((rowSal != null) && (foreignRows != null))) {
237,7 → 243,8
} else {
if (!rowTmp.getString("NOM").equalsIgnoreCase(varCallName)) {
Object ob = checkFormule(rowTmp.getString("FORMULE"), rowTmp.getString("NOM"));
defineVariable(interpreter, bW, rowTmp.getString("NOM"), ob == null ? new Float(1) : ob);
if (ob != null) {
defineVariable(interpreter, bW, rowTmp.getString("NOM"), ob);
}
}
}
244,6 → 251,7
}
}
}
}
 
bW.write(formule);
bW.flush();
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/AbstractArticleItemTable.java
302,7 → 302,8
 
public void setTarif(SQLRowAccessor idTarif, boolean ask) {
this.tarif = idTarif;
if (!this.tarif.isForeignEmpty("ID_DEVISE") && this.defaultRowVals != null) {
// Test si ID_DEVISE est dans la table pour KD
if (this.tarif != null && this.tarif.getTable().contains("ID_DEVISE") && !this.tarif.isForeignEmpty("ID_DEVISE") && this.defaultRowVals != null) {
this.defaultRowVals.put("ID_DEVISE", this.tarif.getForeignID("ID_DEVISE"));
}
}
343,6 → 344,7
if (rowVals.getObject("NIVEAU") != null) {
niveauCourant = rowVals.getInt("NIVEAU");
}
if (niveauCourant > 0) {
if (niveauCourant < niveau || niveauCourant == 1) {
break;
} else if (niveauCourant == niveau) {
352,6 → 354,7
prixUnitHA = prixUnitHA.add(rowVals.getBigDecimal("PA_HT").multiply(new BigDecimal(rowVals.getInt("QTE"))).multiply(rowVals.getBigDecimal("QTE_UNITAIRE")));
}
}
}
if (update) {
final int columnForFieldHA = this.model.getColumnForField("PRIX_METRIQUE_HA_1");
if (columnForFieldHA >= 0) {
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/AbstractAchatArticleItemTable.java
13,28 → 13,6
package org.openconcerto.erp.core.common.ui;
 
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
 
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.ToolTipManager;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellRenderer;
 
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
66,6 → 44,32
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.i18n.TranslationManager;
 
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
 
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellRenderer;
 
public abstract class AbstractAchatArticleItemTable extends AbstractArticleItemTable {
 
private AutoCompletionManager m;
97,7 → 101,7
 
final SQLElement e = getSQLElement();
 
SQLPreferences prefs = SQLPreferences.getMemCached(getSQLElement().getTable().getDBRoot());
final SQLPreferences prefs = SQLPreferences.getMemCached(getSQLElement().getTable().getDBRoot());
final boolean selectArticle = prefs.getBoolean(GestionArticleGlobalPreferencePanel.USE_CREATED_ARTICLE, false);
final boolean createAuto = prefs.getBoolean(GestionArticleGlobalPreferencePanel.CREATE_ARTICLE_AUTO, true);
this.supplierCode = prefs.getBoolean(GestionArticleGlobalPreferencePanel.SUPPLIER_PRODUCT_CODE, false);
191,13 → 195,13
 
SQLTableElement qteU = new SQLTableElement(e.getTable().getField("QTE_UNITAIRE"), BigDecimal.class) {
@Override
public boolean isCellEditable(SQLRowValues vals) {
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
 
SQLRowAccessor row = vals.getForeign("ID_UNITE_VENTE");
if (row != null && !row.isUndefined() && row.getBoolean("A_LA_PIECE")) {
return false;
} else {
return super.isCellEditable(vals);
return super.isCellEditable(vals, rowIndex, columnIndex);
}
}
 
286,11 → 290,21
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
handlePopup(e);
}
 
@Override
public void mousePressed(MouseEvent e) {
handlePopup(e);
}
 
public void handlePopup(MouseEvent e) {
final int rowindex = table.getSelectedRow();
if (rowindex < 0)
return;
if (e.isPopupTrigger() && e.getComponent() instanceof JTable) {
JPopupMenu popup = new JPopupMenu();
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.CAN_EXPAND_NOMENCLATURE_HA, true)) {
popup.add(new AbstractAction(TranslationManager.getInstance().getTranslationForItem("product.bom.expand")) {
 
@Override
312,7 → 326,7
expandNomenclature(rowindex, m, EXPAND_TYPE.FLAT);
}
});
 
}
for (AbstractAction action : getAdditionnalMouseAction(rowindex)) {
popup.add(action);
}
324,6 → 338,9
 
// Autocompletion
List<String> completionFields = new ArrayList<String>();
if (e.getTable().getFieldsName().contains("INCOTERM")) {
completionFields.add("INCOTERM");
}
completionFields.add("ID_UNITE_VENTE");
completionFields.add("PA_HT");
completionFields.add("PV_HT");
345,9 → 362,7
if (e.getTable().getFieldsName().contains("COLORIS")) {
completionFields.add("COLORIS");
}
if (e.getTable().getFieldsName().contains("INCOTERM")) {
completionFields.add("INCOTERM");
}
 
if (e.getTable().getFieldsName().contains("DESCRIPTIF")) {
completionFields.add("DESCRIPTIF");
}
670,7 → 685,9
}
 
});
 
// La devise est renseignée globalement dans la commande et est reportée automatiquement sur
// les lignes
setColumnVisible(model.getColumnIndexForElement(tableElement_Devise), false);
for (String string : visibilityMap.keySet()) {
setColumnVisible(model.getColumnForField(string), visibilityMap.get(string));
}
689,8 → 706,19
return Collections.emptyList();
}
 
private String incoterm = "";
 
public void setIncoterms(String incoterm) {
if (incoterm == null) {
incoterm = "";
}
this.incoterm = incoterm;
}
 
private SQLRow rowFournisseur = null;
 
public void setFournisseur(SQLRow rowFournisseur) {
 
this.rowFournisseur = rowFournisseur;
if (getSQLElement().getTable().contains("ID_CODE_FOURNISSEUR") && this.supplierCode) {
 
if (rowFournisseur != null && !rowFournisseur.isUndefined()) {
715,59 → 743,112
}
 
private Object tarifCompletion(SQLRow row, String field) {
final SQLTable tTarifFournisseur = row.getTable().getDBRoot().getTable("ARTICLE_TARIF_FOURNISSEUR");
final SQLTable tTarifFournisseur = this.getSQLElement().getTable().getDBRoot().getTable("ARTICLE_TARIF_FOURNISSEUR");
 
if (field.equalsIgnoreCase("PRIX_METRIQUE_HA_1") && tTarifFournisseur != null) {
List<SQLRow> rows = row.getReferentRows(tTarifFournisseur);
if (!rows.isEmpty()) {
final SQLRow sqlRow0 = rows.get(0);
 
if (row != null && !row.isUndefined() && field.equalsIgnoreCase("PRIX_METRIQUE_HA_1") && tTarifFournisseur != null) {
List<String> incoTerms;
final String conditionsInco = sqlRow0.getString("CONDITIONS");
 
if (conditionsInco != null && conditionsInco.equalsIgnoreCase("CPT")) {
if (this.incoterm != null && this.incoterm.equalsIgnoreCase("CPT")) {
incoTerms = Arrays.asList("PRIX_ACHAT", "COEF_TRANSPORT_PORT");
} else if (conditionsInco != null && conditionsInco.equalsIgnoreCase("DDP")) {
} else if (this.incoterm != null && this.incoterm.equalsIgnoreCase("DDP")) {
incoTerms = Arrays.asList("PRIX_ACHAT", "COEF_TRANSPORT_PORT", "COEF_TAXE_D");
} else {
incoTerms = Arrays.asList("PRIX_ACHAT");
}
List<SQLRow> rows = row.getReferentRows(tTarifFournisseur);
if (row.getBoolean("AUTO_PRIX_ACHAT_NOMENCLATURE")) {
 
BigDecimal min = getPrice(sqlRow0, incoTerms);
List<SQLRow> rowsElt = row.getReferentRows(row.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
BigDecimal price = BigDecimal.ZERO;
final Set<String> tarifNotFound = new HashSet<String>();
for (SQLRow sqlRow : rowsElt) {
List<SQLRow> rowsT = sqlRow.getForeign("ID_ARTICLE").getReferentRows(tTarifFournisseur);
 
boolean priceFound = false;
boolean tarifFound = false;
if (rowsT.size() > 0) {
BigDecimal min = BigDecimal.ZERO;
 
BigDecimal defaultPrice = BigDecimal.ZERO;
Calendar c = null;
for (SQLRow sqlRowT : rowsT) {
if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRowT.getForeignID("ID_FOURNISSEUR")) {
BigDecimal priceT = getPrice(sqlRowT, incoTerms);
defaultPrice = priceT;
final Calendar datePrice = sqlRowT.getDate("DATE_PRIX");
if (datePrice == null || (this.getDateDevise() != null && !this.getDateDevise().before(datePrice.getTime()))) {
if (c == null || c.before(datePrice)) {
 
min = priceT;
c = datePrice;
priceFound = true;
} else if (c != null) {
defaultPrice = priceT;
}
}
tarifFound = true;
}
}
 
if (priceFound) {
price = price.add(min.multiply(sqlRow.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRow.getInt("QTE"), DecimalUtils.HIGH_PRECISION))));
} else {
price = price.add(defaultPrice.multiply(sqlRow.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRow.getInt("QTE"), DecimalUtils.HIGH_PRECISION))));
}
}
if (!tarifFound) {
tarifNotFound.add(sqlRow.getForeign("ID_ARTICLE").getString("CODE"));
}
}
if (!tarifNotFound.isEmpty()) {
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
JOptionPane.showMessageDialog(AbstractAchatArticleItemTable.this.table,
"Attention, impossible de calculer le tarif.\nLes articles suivants n'ont pas de tarif associé :\n" + tarifNotFound);
}
});
}
return price;
} else if (!rows.isEmpty()) {
BigDecimal min = BigDecimal.ZERO;
Calendar c = null;
for (SQLRow sqlRow : rows) {
if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRow.getForeignID("ID_FOURNISSEUR")) {
BigDecimal price = getPrice(sqlRow, incoTerms);
if (price.compareTo(min) < 0) {
final Calendar datePrice = sqlRow.getDate("DATE_PRIX");
if (datePrice == null || (this.getDateDevise() != null && !this.getDateDevise().before(datePrice.getTime()))) {
if (c == null || c.before(datePrice)) {
min = price;
c = datePrice;
}
}
}
}
return min.setScale(2, RoundingMode.HALF_UP);
}
}
if (field.equalsIgnoreCase("INCOTERM")) {
if (tTarifFournisseur != null) {
List<SQLRow> rows = row.getReferentRows(tTarifFournisseur);
if (!rows.isEmpty()) {
final SQLRow sqlRow0 = rows.get(0);
return sqlRow0.getString("CONDITIONS");
// if (tTarifFournisseur != null) {
// List<SQLRow> rows = row.getReferentRows(tTarifFournisseur);
// if (!rows.isEmpty()) {
// final SQLRow sqlRow0 = rows.get(0);
// return sqlRow0.getString("CONDITIONS");
// }
// }
return this.incoterm;
}
}
return "";
}
 
if (getDevise() != null && !getDevise().isUndefined()) {
if ((field.equalsIgnoreCase("ID_DEVISE") || field.equalsIgnoreCase("ID_DEVISE_HA"))) {
return getDevise().getID();
} else if ((field.equalsIgnoreCase("PA_DEVISE"))) {
if (row.getBigDecimal("PA_DEVISE") != null && row.getBigDecimal("PA_DEVISE").signum() != 0) {
if (row.getBigDecimal("PA_DEVISE") != null && row.getBigDecimal("PA_DEVISE").signum() != 0 && this.incoterm.length() == 0) {
return row.getBigDecimal("PA_DEVISE");
} else {
if (row.getBigDecimal("PA_DEVISE") != null && row.getBigDecimal("PA_DEVISE").signum() != 0) {
return row.getBigDecimal("PA_DEVISE");
} else {
String devCode = getDevise().getString("CODE");
 
CurrencyConverter c = new CurrencyConverter();
BigDecimal tarifCompletion = (BigDecimal) tarifCompletion(row, "PRIX_METRIQUE_HA_1");
if (tarifCompletion == null) {
tarifCompletion = row.getBigDecimal("PRIX_METRIQUE_HA_1");
775,11 → 856,13
if (tarifCompletion == null) {
return null;
} else {
return convert(tarifCompletion, devCode, true).setScale(2, RoundingMode.HALF_UP);
// Remove set scale 2 --> if scale ex : PA = 95.74MAD --> 0.76592€
// with Scale 0.77€ so put 96.25MAD in PA
return convert(tarifCompletion, devCode, true);
}
}
 
}
}
} else {
if ((field.equalsIgnoreCase("ID_DEVISE") || field.equalsIgnoreCase("ID_DEVISE_HA"))) {
return Configuration.getInstance().getDirectory().getElement("DEVISE").getTable().getUndefinedID();
789,6 → 872,7
}
}
return null;
 
}
 
@Override
/trunk/OpenConcerto/src/org/openconcerto/erp/core/common/ui/Acompte.java
13,6 → 13,8
package org.openconcerto.erp.core.common.ui;
 
import org.openconcerto.erp.core.finance.accounting.model.Currency;
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.GestionDevise;
import org.openconcerto.utils.StringUtils;
23,6 → 25,7
public class Acompte {
protected BigDecimal montant;
protected BigDecimal percent;
private CurrencyConverter converter = new CurrencyConverter();
 
public final static Acompte HUNDRED_PERCENT = new Acompte(new BigDecimal(100), null);
 
41,13 → 44,17
this.percent = percent;
}
 
public String toPlainString() {
public String toPlainString(boolean withCurrencySymbol) {
if (percent != null) {
DecimalFormat format = new DecimalFormat("##0.00");
return format.format(percent) + "%";
} else if (montant != null) {
DecimalFormat format = new DecimalFormat("###,##0.00");
return format.format(montant);
String string = format.format(montant);
if (withCurrencySymbol) {
string = string + Currency.getSymbol(converter.getCompanyCurrencyCode());
}
return string;
} else {
return "";
}