OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 155 → Rev 156

/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/order/action/ListeDesElementsACommanderClientAction.java
13,11 → 13,13
package org.openconcerto.erp.core.sales.order.action;
 
import org.openconcerto.erp.action.CreateFrameAbstractAction;
import org.openconcerto.erp.action.CreateIListFrameAbstractAction;
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
import org.openconcerto.erp.core.sales.order.element.CommandeClientElementSQLElement;
import org.openconcerto.sql.Configuration;
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.FieldPath;
import org.openconcerto.sql.model.FieldRef;
28,16 → 30,17
import org.openconcerto.sql.model.SQLSelectJoin;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.model.graph.Path;
import org.openconcerto.sql.preferences.SQLPreferences;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.ListeAddPanel;
import org.openconcerto.sql.view.IListPanel;
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
import org.openconcerto.sql.view.list.SQLTableModelSource;
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.ui.state.WindowStateManager;
import org.openconcerto.utils.CollectionUtils;
import org.openconcerto.utils.DecimalUtils;
import org.openconcerto.utils.cc.ITransformer;
45,7 → 48,6
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collection;
53,36 → 55,23
import java.util.Set;
 
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
public class ListeDesElementsACommanderClientAction extends CreateFrameAbstractAction {
final CommandeClientElementSQLElement eltCmd = (CommandeClientElementSQLElement) Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
public class ListeDesElementsACommanderClientAction extends CreateIListFrameAbstractAction<CommandeClientElementSQLElement> {
 
public ListeDesElementsACommanderClientAction() {
super();
this.putValue(Action.NAME, "Liste des éléments en attente de livraison");
public ListeDesElementsACommanderClientAction(final ComptaPropsConfiguration conf) {
super(conf, CommandeClientElementSQLElement.class);
}
 
private BaseSQLTableModelColumn colAvancement;
 
public JFrame createFrame() {
final JFrame frame = new JFrame("Eléments en attente de livraison");
// Actions
 
final JPanel orderPanel = createPanel();
 
frame.getContentPane().add(orderPanel);
FrameUtil.setBounds(frame);
final File file = IListFrame.getConfigFile(eltCmd, frame.getClass());
if (file != null)
new WindowStateManager(frame, file).loadState();
return frame;
@Override
protected String getPanelVariant() {
return this.getClass().getSimpleName();
}
 
JPanel createPanel() {
final SQLTableModelSourceOnline tableSource = eltCmd.getTableSource(true);
@Override
protected SQLTableModelSource createTableSource() {
final SQLTableModelSource tableSource = super.createTableSource();
final CommandeClientElementSQLElement eltCmd = getElem();
tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
 
@Override
94,12 → 83,15
final String quoteQteU = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE_UNITAIRE").quote();
Where w = Where.createRaw(quoteQteL + " < (" + quoteQte + "*" + quoteQteU + ")", eltCmd.getTable().getField("QTE_LIVREE"), eltCmd.getTable().getField("QTE"),
eltCmd.getTable().getField("QTE_UNITAIRE"));
w = w.and(new Where(eltCmd.getTable().getField("LIVRE_FORCED"), "=", Boolean.FALSE));
input.setWhere(w);
return input;
}
});
 
BaseSQLTableModelColumn colStockR = new BaseSQLTableModelColumn("Stock Reel", Float.class) {
SQLPreferences prefs = SQLPreferences.getMemCached(eltCmd.getTable().getDBRoot());
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
BaseSQLTableModelColumn colStockD = new BaseSQLTableModelColumn("Dépôt", String.class) {
 
@Override
protected Object show_(SQLRowAccessor r) {
106,12 → 98,12
 
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
if (foreign != null && !foreign.isUndefined()) {
final SQLRowAccessor foreign2 = foreign.getForeign("ID_STOCK");
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
if (foreign2 != null && !foreign2.isUndefined()) {
return foreign2.getFloat("QTE_REEL");
return foreign2.getForeign("ID_DEPOT_STOCK").getString("NOM");
}
}
return 0F;
return "";
}
 
@Override
118,22 → 110,24
public Set<FieldPath> getPaths() {
Path p = new Path(eltCmd.getTable());
p = p.add(p.getLast().getField("ID_ARTICLE"));
p = p.add(p.getLast().getField("ID_STOCK"));
return CollectionUtils.createSet(new FieldPath(p, "QTE_REEL"));
Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
Path p3 = p2.add(p2.getLast().getField("ID_DEPOT_STOCK"));
Path p4 = p.add(p.getLast().getField("ID_DEPOT_STOCK"));
return CollectionUtils.createSet(new FieldPath(p3, "NOM"), new FieldPath(p4, "NOM"));
}
};
tableSource.getColumns().add(colStockR);
tableSource.getColumns().add(colStockD);
}
BaseSQLTableModelColumn colStockR = new BaseSQLTableModelColumn("Stock Reel", Float.class) {
 
BaseSQLTableModelColumn colLiv2 = new BaseSQLTableModelColumn("Stock TH", Float.class) {
 
@Override
protected Object show_(SQLRowAccessor r) {
 
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
if (foreign != null && !foreign.isUndefined()) {
final SQLRowAccessor foreign2 = foreign.getForeign("ID_STOCK");
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
if (foreign2 != null && !foreign2.isUndefined()) {
return foreign2.getFloat("QTE_TH");
return foreign2.getFloat("QTE_REEL");
}
}
return 0F;
143,133 → 137,95
public Set<FieldPath> getPaths() {
Path p = new Path(eltCmd.getTable());
p = p.add(p.getLast().getField("ID_ARTICLE"));
p = p.add(p.getLast().getField("ID_STOCK"));
return CollectionUtils.createSet(new FieldPath(p, "QTE_TH"));
Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_REEL"), new FieldPath(p2, "ID_DEPOT_STOCK"));
}
};
tableSource.getColumns().add(colLiv2);
tableSource.getColumns().add(colStockR);
 
BaseSQLTableModelColumn colStockMin = new BaseSQLTableModelColumn("Stock Min", Integer.class) {
BaseSQLTableModelColumn colLiv2 = new BaseSQLTableModelColumn("Stock TH", Float.class) {
 
@Override
protected Object show_(SQLRowAccessor r) {
 
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
return foreign.getInt("QTE_MIN");
if (foreign != null && !foreign.isUndefined()) {
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
if (foreign2 != null && !foreign2.isUndefined()) {
return foreign2.getFloat("QTE_TH");
}
}
return 0F;
}
 
@Override
public Set<FieldPath> getPaths() {
Path p = new Path(eltCmd.getTable());
p = p.add(p.getLast().getField("ID_ARTICLE"));
 
return CollectionUtils.createSet(new FieldPath(p, "QTE_MIN"));
Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_TH"), new FieldPath(p2, "ID_DEPOT_STOCK"));
}
};
tableSource.getColumns().add(colStockMin);
tableSource.getColumns().add(colLiv2);
 
BaseSQLTableModelColumn colSug = new BaseSQLTableModelColumn("Qtè à commander", Float.class) {
BaseSQLTableModelColumn colStockMin = new BaseSQLTableModelColumn("Stock Min", Float.class) {
 
@Override
protected Object show_(SQLRowAccessor r) {
 
// final float qteCommande = r.getBigDecimal("QTE_UNITAIRE").multiply(new
// BigDecimal(r.getInt("QTE"))).subtract(r.getBigDecimal("QTE_LIVREE")).floatValue();
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
if (foreign != null && !foreign.isUndefined()) {
float qteMin = foreign.getFloat("QTE_MIN");
final SQLRowAccessor foreign2 = foreign.getForeign("ID_STOCK");
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
if (foreign2 != null && !foreign2.isUndefined()) {
float manque = foreign2.getFloat("QTE_TH") - qteMin;
if (manque < 0) {
return -manque;
return foreign2.getFloat("QTE_MIN");
}
}
}
return 0F;
}
 
@Override
public Set<FieldPath> getPaths() {
Path pA = new Path(eltCmd.getTable());
 
pA = pA.add(pA.getLast().getField("ID_ARTICLE"));
Path p = pA.add(pA.getLast().getField("ID_STOCK"));
return CollectionUtils.createSet(new FieldPath(pA, "QTE_MIN"), new FieldPath(p, "QTE_TH"));
Path p = new Path(eltCmd.getTable());
p = p.add(p.getLast().getField("ID_ARTICLE"));
Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_MIN"), new FieldPath(p2, "ID_DEPOT_STOCK"));
}
};
tableSource.getColumns().add(colSug);
// colLiv2.setRenderer(new PercentTableCellRenderer());
tableSource.getColumns().add(colStockMin);
 
final ListeAddPanel panel = getPanel(eltCmd, tableSource);
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Calcul des besoins") {
 
@Override
public void actionPerformed(ActionEvent e) {
final SQLElement artElt = eltCmd.getForeignElement("ID_ARTICLE");
final SQLTableModelSourceOnline createTableSource = artElt.createTableSource();
createTableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
@Override
public SQLSelect transformChecked(SQLSelect input) {
FieldRef refStock = input.getAlias(artElt.getTable().getForeignTable("ID_STOCK").getField("QTE_TH"));
 
SQLSelectJoin j = input.getJoinFromField(artElt.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
Where w = new Where(refStock, "<", artElt.getTable().getField("QTE_MIN"));
w = w.and(new Where(j.getJoinedTable().getKey(), "=", (Object) null));
input.setWhere(w);
// input.setHaving(Where.createRaw("COUNT(\"" + j.getJoinedTable().getKey()
// + "\")" + " = 0", Arrays.asList(j.getJoinedTable().getKey())));
return input;
}
});
 
BaseSQLTableModelColumn colSug = new BaseSQLTableModelColumn("Qtè à commander", Float.class) {
 
@Override
protected Object show_(SQLRowAccessor r) {
 
float qteMin = r.getFloat("QTE_MIN");
final SQLRowAccessor foreign2 = r.getForeign("ID_STOCK");
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
if (foreign != null && !foreign.isUndefined()) {
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
if (foreign2 != null && !foreign2.isUndefined()) {
float qteMin = foreign2.getFloat("QTE_MIN");
float manque = foreign2.getFloat("QTE_TH") - qteMin;
if (manque < 0) {
return -manque;
}
}
}
return 0F;
 
return 0F;
}
 
@Override
public Set<FieldPath> getPaths() {
Path pA = new Path(artElt.getTable());
 
Path p = pA.add(pA.getLast().getField("ID_STOCK"));
return CollectionUtils.createSet(new FieldPath(pA, "QTE_MIN"), new FieldPath(p, "QTE_TH"));
Path p = new Path(eltCmd.getTable());
p = p.add(p.getLast().getField("ID_ARTICLE"));
Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_TH"), new FieldPath(p2, "QTE_MIN"), new FieldPath(p2, "ID_DEPOT_STOCK"));
}
};
createTableSource.getColumns().add(colSug);
tableSource.getColumns().add(colSug);
// colLiv2.setRenderer(new PercentTableCellRenderer());
 
IListe listeArt = new IListe(createTableSource);
final PredicateRowAction predicateACtion = new PredicateRowAction(new AbstractAction("Passer une commande fournisseur") {
 
@Override
public void actionPerformed(ActionEvent e) {
List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
eltCmd.createCommandeF(selectedRows);
return tableSource;
}
}, true);
predicateACtion.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
listeArt.addIListeAction(predicateACtion);
ListeViewPanel p = new ListeViewPanel(artElt, listeArt);
IListFrame f = new IListFrame(p);
FrameUtil.show(f);
}
}, true);
action.setPredicate(IListeEvent.createTotalRowCountPredicate(0, Integer.MAX_VALUE));
panel.getListe().addIListeAction(action);
return panel;
}
 
private BigDecimal getAvancementLFromBL(SQLRowAccessor r) {
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("COMMANDE_CLIENT_ELEMENT"));
291,9 → 247,10
}
}
 
private ListeAddPanel getPanel(final SQLElement eltCmd, final SQLTableModelSourceOnline tableSource) {
final ListeAddPanel panel = new ListeAddPanel(eltCmd, new IListe(tableSource));
 
@Override
protected IListPanel instantiateListPanel(SQLTableModelSource tableSource, String panelVariant) {
final IListPanel panel = super.instantiateListPanel(tableSource, panelVariant);
final CommandeClientElementSQLElement eltCmd = getElem();
// final List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new
// ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(2);
// fields.add(Tuple2.create(panel.getListe().getSource().getColumn(eltCmd.getTable().getField("T_HT")),
329,6 → 286,48
// bottomPanel.add(totalPanel, c2);
 
panel.add(bottomPanel, c);
 
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Calcul des besoins") {
 
@Override
public void actionPerformed(ActionEvent e) {
final SQLElement artElt = eltCmd.getForeignElement("ID_ARTICLE");
final SQLTableModelSourceOnline createTableSource = artElt.createTableSource();
createTableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
@Override
public SQLSelect transformChecked(SQLSelect input) {
FieldRef refStock = input.getAlias(artElt.getTable().getForeignTable("ID_STOCK").getField("QTE_TH"));
 
SQLSelectJoin j = input.getJoinFromField(artElt.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
Where w = new Where(refStock, "<", artElt.getTable().getField("QTE_MIN"));
w = w.and(new Where(j.getJoinedTable().getKey(), "=", (Object) null));
input.setWhere(w);
// input.setHaving(Where.createRaw("COUNT(\"" + j.getJoinedTable().getKey()
// + "\")" + " = 0", Arrays.asList(j.getJoinedTable().getKey())));
return input;
}
});
 
IListe listeArt = new IListe(createTableSource);
final PredicateRowAction predicateACtion = new PredicateRowAction(new AbstractAction("Passer une commande fournisseur") {
 
@Override
public void actionPerformed(ActionEvent e) {
List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
eltCmd.createCommandeF(selectedRows);
}
}, true);
predicateACtion.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
listeArt.addIListeAction(predicateACtion);
ListeViewPanel p = new ListeViewPanel(artElt, listeArt);
IListFrame f = new IListFrame(p);
FrameUtil.show(f);
}
 
}, true);
action.setPredicate(IListeEvent.createTotalRowCountPredicate(0, Integer.MAX_VALUE));
panel.getListe().addIListeAction(action);
 
return panel;
}