Dépôt officiel du code source de l'ERP OpenConcerto
Blame | Last modification | View Log | RSS feed
/*
* 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");
}
}