use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class VOrderDistributionReceipt method executeQuery.
/**
* Query Info
*/
private void executeQuery() {
log.info("");
String sql = "";
if (m_DD_Order_ID == null)
return;
sql = getOrderSQL();
log.fine(sql);
// reset table
int row = 0;
miniTable.setRowCount(row);
// Execute
try {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, Integer.parseInt(m_DD_Order_ID.toString()));
ResultSet rs = pstmt.executeQuery();
//
while (rs.next()) {
// extend table
miniTable.setRowCount(row + 1);
// set values
// DD_Order_ID
miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0);
// QtyInTransit
miniTable.setValueAt(rs.getBigDecimal(2), row, 1);
// C_UOM_ID
miniTable.setValueAt(rs.getString(3), row, 2);
// Value
miniTable.setValueAt(rs.getString(4), row, 4);
// M_Product_ID
miniTable.setValueAt(rs.getString(5), row, 3);
// WarehouseSource
miniTable.setValueAt(rs.getString(6), row, 5);
//miniTable.setValueAt(rs.getBigDecimal(7), row, 6); // QtyBackOrder
// prepare next
row++;
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
}
//
miniTable.autoSize();
// statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class WFActivity method loadActivities.
/**
* Load Activities
* @return int
*/
public int loadActivities() {
resetDisplay(null);
while (selTableModel.getRowCount() > 0) selTableModel.removeRow(0);
long start = System.currentTimeMillis();
ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
String sql = "SELECT * FROM AD_WF_Activity a " + "WHERE a.Processed='N' AND a.WFState='OS' AND (" + // Owner of Activity
" a.AD_User_ID=?" + // Invoker (if no invoker = all)
" OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + // #2
" AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" + // Responsible User
" OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + // #3
" AND r.AD_User_ID=?)" + // Responsible Role
" OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)" + // #4
" WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" + //
") ORDER BY a.Priority DESC, Created";
int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
sql = role.addAccessSQL(sql, "a", true, false);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_User_ID);
pstmt.setInt(2, AD_User_ID);
pstmt.setInt(3, AD_User_ID);
pstmt.setInt(4, AD_User_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
MWFActivity activity = new MWFActivity(Env.getCtx(), rs, null);
Object[] rowData = new Object[4];
rowData[0] = new IDColumn(activity.get_ID());
rowData[1] = activity.getPriority();
rowData[2] = activity.getNodeName();
rowData[3] = activity.getSummary();
selTableModel.addRow(rowData);
if (list.size() > MAX_ACTIVITIES_IN_LIST) {
log.warning("More than " + MAX_ACTIVITIES_IN_LIST + " Activities - ignored");
break;
}
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
selTable.autoSize(false);
log.fine("#" + selTable.getModel().getRowCount() + "(" + (System.currentTimeMillis() - start) + "ms)");
return selTable.getModel().getRowCount();
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class InfoProduct method enableButtons.
/**
* Enable PAttribute if row selected/changed
*/
protected void enableButtons() {
if (m_PAttributeButton != null) {
if (p_table == null)
return;
int row = p_table.getSelectionModel().getLeadSelectionIndex();
int rows = p_table.getRowCount();
if (p_table.getShowTotals())
rows = rows - 1;
if (row < 0 || row > rows) {
super.enableButtons();
return;
}
boolean enabled = false;
// Check the lead row - if it has no attribute instances, no button
try {
Object value = p_table.getValueAt(row, INDEX_PATTRIBUTE);
enabled = Boolean.TRUE.equals(value);
} catch (Exception e) {
enabled = false;
}
if (enabled && p_table.isMultiSelection()) {
// Only enable if a single row is selected. Disable for multiple selections.
// Multiple selections can be checked or just high-lighted.
int checkedRows = p_table.getSelectedKeys().size();
int selectedRows = p_table.getSelectedRowCount();
log.fine("Checked Rows: " + checkedRows + " SelectedRows: " + selectedRows);
if (checkedRows > 1 || selectedRows > 1)
enabled = false;
else if (// SelectedRows could be zero so don't care
checkedRows == 1) {
//Check that the lead selection is checked
Object data = p_table.getValueAt(row, p_table.getKeyColumnIndex());
if (data instanceof IDColumn) {
IDColumn record = (IDColumn) data;
if (!record.isSelected()) {
enabled = false;
log.fine("Lead selection is not checked!");
}
}
}
}
m_PAttributeButton.setEnabled(enabled);
}
super.enableButtons();
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class InfoProduct method refreshAtpTab.
// initAtpTab
/**
* Refresh ATP
*/
private void refreshAtpTab() {
boolean showDetail = checkShowDetail.isSelected();
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
int M_Warehouse_ID = 0;
// row to prevent array index out of bounds. BF 3051361
if (warehouseTbl.getRowCount() > 0) {
int selectedRow = warehouseTbl.getSelectedRow();
if (selectedRow < 0)
selectedRow = 0;
Object wh_data = warehouseTbl.getValueAt(selectedRow, warehouseTbl.getKeyColumnIndex());
if (wh_data != null && wh_data instanceof IDColumn) {
IDColumn dataColumn = (IDColumn) wh_data;
M_Warehouse_ID = dataColumn.getRecord_ID();
}
} else {
M_Warehouse_ID = m_M_Warehouse_ID;
}
if (M_Warehouse_ID == 0) {
// Can't find a warehouse to load. Clear the table
clearAtpTab();
return;
} else // Update the table
{
// Create the SELECT ..UNION. clause
// This is done in-line rather than using prepareTable() so we can add a running sum to the data.
String sql;
if (!showDetail)
sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, 0 as ID, null as Date," + " sum(s.QtyOnHand) as AvailQty, null as DeltaQty, sum(s.QtyOrdered) as QtyOrdered, sum(s.QtyReserved) as QtyReserved," + // " s.PASI,"
" null as sumPASI," + " 0 as ASI," + " null as BP_Name, null as DocumentNo, 10 as SeqNo";
else
sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, s.M_AttributeSetInstance_ID as ID, now() as Date," + " s.QtyOnHand as AvailQty, null as DeltaQty, s.QtyOrdered as QtyOrdered, s.QtyReserved as QtyReserved," + " CASE WHEN s.PASI = '' THEN '{' || COALESCE(s.M_AttributeSetInstance_ID,0) || '}' ELSE s.PASI END as sumPASI," + " COALESCE(M_AttributeSetInstance_ID,0) as ASI," + " null as BP_Name, null as DocumentNo, 10 as SeqNo";
sql += " FROM (SELECT M_Product_ID, M_Locator_ID, QtyOnHand, QtyReserved, QtyOrdered," + " COALESCE(productAttribute(M_AttributeSetInstance_ID)::varchar, '') as PASI," + " COALESCE(M_AttributeSetInstance_ID,0) as M_AttributeSetInstance_ID FROM M_Storage) s " + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " AND s.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND l.M_Warehouse_ID=" + M_Warehouse_ID;
// sql += " AND s.M_AttributeSetInstance_ID=?";
if (!showDetail) {
//sql += " AND (s.QtyOnHand<>0)";
sql += " GROUP BY s.M_Product_ID, w.Name, l.value, s.M_Locator_ID, sumPASI, ASI, BP_Name, DocumentNo, SeqNo ";
} else
//sql += " AND (s.QtyOnHand<>0) ";
;
sql += " UNION ALL ";
// Orders
sql += "SELECT ol.M_Product_ID, w.Name as warehouse, null as locator, ol.M_AttributeSetInstance_ID as ID, o.DatePromised as date," + " null as AvailQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE -ol.QtyReserved END as DeltaQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE null END as QtyOrdered," + " CASE WHEN dt.DocBaseType = 'POO' THEN 0 ELSE 0 END as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM C_Order o" + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO')" + " AND ol.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
//if (m_M_AttributeSetInstance_ID > 0)
// sql += " AND ol.M_AttributeSetInstance_ID=?";
//sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator";
sql += " UNION ALL ";
// Distribution Orders out bound
sql += "SELECT ol.M_Product_ID, wf.Name as warehouse, lf.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " -ol.QtyOrdered+ol.QtyInTransit+ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (o.C_BPartner_ID = bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered = 'N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND wf.M_Warehouse_ID=" + M_Warehouse_ID;
//if (m_M_AttributeSetInstance_ID > 0)
// sql += " AND ol.M_AttributeSetInstance_ID=?";
sql += " UNION ALL ";
// Distribution Orders in bound
sql += "SELECT ol.M_Product_ID, w.Name as warehouse, l.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " ol.QtyOrdered-ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (wf.AD_Org_ID=bp.AD_OrgBP_ID) " + "WHERE ol.QtyOrdered - ol.Qtydelivered > 0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered='N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
//if (m_M_AttributeSetInstance_ID > 0)
// sql += " AND ol.M_AttributeSetInstance_ID=?";
sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator)";
double qty = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
int index = 1;
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
// The order of data matches the layout, not the query
// M_Product_ID, warehouse, locator, ID, Date, AvailQty, DeltaQty, (1..7)
// QtyOrdered, QtyReserved, (8..9)
// sumPASI, ASI, (10..11)
// BP_Name, DocumentNo, SeqNo (12..14)
Vector<Object> line = new Vector<Object>(10);
// M_Product_ID
line.add(rs.getInt(1));
// warehouse
line.add(rs.getString(2));
// Locator
line.add(rs.getString(3));
// Date
line.add(rs.getTimestamp(5));
double deltaQty = rs.getDouble(7);
qty += +rs.getDouble(6) + deltaQty;
// Qty Available (running sum)
line.add(new Double(qty) - rs.getDouble(9));
// Qty on hand (this line)
line.add(new Double(rs.getDouble(6)));
// Delta Qty
line.add(new Double(rs.getDouble(7)));
// BPartner
line.add(rs.getString(12));
// QtyOrdered
line.add(new Double(rs.getDouble(8)));
// QtyReserved
line.add(new Double(rs.getDouble(9)));
// ASI
line.add(rs.getString(10));
// DocumentNo
line.add(rs.getString(13));
data.add(line);
}
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
// Update the table
// Header
Vector<String> columnNames = new Vector<String>();
for (int i = 0; i < m_layoutATP.length; i++) {
columnNames.add(m_layoutATP[i].getColHeader());
}
m_modelAtp = new DefaultTableModel();
m_modelAtp.setDataVector(data, columnNames);
// Avoid an exception
SwingUtilities.invokeLater(new Runnable() {
public void run() {
m_tableAtp.setModel(m_modelAtp);
// set editors (two steps)
for (int i = 0; i < m_layoutATP.length; i++) {
m_tableAtp.setColumnClass(i, m_layoutATP[i].getColClass(), m_layoutATP[i].isReadOnly(), m_layoutATP[i].getColHeader());
if (m_layoutATP[i].isColorColumn()) {
// QtyAvailable.
m_tableAtp.setColorColumn(i);
}
}
m_tableAtp.autoSize();
}
});
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class InfoPanel method readData.
private void readData(ResultSet rs) throws SQLException {
// columns start with 1
int colOffset = 1;
List<Object> data = new ArrayList<Object>();
for (int col = 0; col < p_layout.length; col++) {
Object value = null;
Class<?> c = p_layout[col].getColClass();
int colIndex = col + colOffset;
if (c == IDColumn.class) {
value = new IDColumn(rs.getInt(colIndex));
} else if (c == Boolean.class)
value = new Boolean("Y".equals(rs.getString(colIndex)));
else if (c == Timestamp.class)
value = rs.getTimestamp(colIndex);
else if (c == BigDecimal.class)
value = rs.getBigDecimal(colIndex);
else if (c == Double.class)
value = new Double(rs.getDouble(colIndex));
else if (c == Integer.class)
value = new Integer(rs.getInt(colIndex));
else if (c == KeyNamePair.class) {
String display = rs.getString(colIndex);
int key = rs.getInt(colIndex + 1);
value = new KeyNamePair(key, display);
colOffset++;
} else {
value = rs.getString(colIndex);
}
data.add(value);
}
line.add(data);
}
Aggregations