use of org.compiere.model.Query in project adempiere by adempiere.
the class ExportHelper method exportRecord.
/**
* * Process - Generate Export Format
* @param exportFormat
* @param where
* @param replicationMode
* @param replicationType
* @param replicationEvent
* @return
* @throws Exception
*/
public Document exportRecord(MEXPFormat exportFormat, String where, Integer replicationMode, String replicationType, Integer replicationEvent) throws Exception {
MClient client = MClient.get(exportFormat.getCtx(), clientId);
MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID());
log.info("Table = " + table);
Collection<PO> records = new Query(exportFormat.getCtx(), table.getTableName(), exportFormat.getWhereClause(), exportFormat.get_TrxName()).setOnlyActiveRecords(true).list();
for (PO po : records) {
log.info("Client = " + client.toString());
log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID());
log.finest("po.get_TrxName() = " + po.get_TrxName());
if (po.get_TrxName() == null || po.get_TrxName().equals("")) {
po.set_TrxName("exportRecord");
}
if (po.get_KeyColumns().length < 1) {
//TODO: Create Mesagge.
throw new Exception(Msg.getMsg(po.getCtx(), "ExportNoneColumnKeyNotSupported"));
}
outDocument = createNewDocument();
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
rootElement.setAttribute("ReplicationMode", replicationMode.toString());
rootElement.setAttribute("ReplicationType", replicationType);
rootElement.setAttribute("ReplicationEvent", replicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
}
// finish record read
return outDocument;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class DistributionRun method insertDetailsDistributionDemand.
// createOrders
/**
* Insert Details
* @return number of rows inserted
*/
private int insertDetailsDistributionDemand() {
// Handle NULL
String sql = "UPDATE M_DistributionRunLine SET MinQty = 0 WHERE MinQty IS NULL";
int no = DB.executeUpdate(sql, get_TrxName());
sql = "UPDATE M_DistributionListLine SET MinQty = 0 WHERE MinQty IS NULL";
no = DB.executeUpdate(sql, get_TrxName());
// Delete Old
sql = "DELETE FROM T_DistributionRunDetail WHERE M_DistributionRun_ID=" + p_M_DistributionRun_ID;
no = DB.executeUpdate(sql, get_TrxName());
log.fine("insertDetails - deleted #" + no);
// Insert New
sql = "INSERT INTO T_DistributionRunDetail " + "(M_DistributionRun_ID, M_DistributionRunLine_ID, M_DistributionList_ID, M_DistributionListLine_ID," + "AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy," + "C_BPartner_ID, C_BPartner_Location_ID, M_Product_ID," + "Ratio, MinQty, Qty) " + "SELECT MAX(rl.M_DistributionRun_ID), MAX(rl.M_DistributionRunLine_ID),MAX(ll.M_DistributionList_ID), MAX(ll.M_DistributionListLine_ID), " + "MAX(rl.AD_Client_ID),MAX(rl.AD_Org_ID), MAX(rl.IsActive), MAX(rl.Created),MAX(rl.CreatedBy), MAX(rl.Updated),MAX(rl.UpdatedBy), " + "MAX(ll.C_BPartner_ID), MAX(ll.C_BPartner_Location_ID), MAX(rl.M_Product_ID)," + // Ration for this process is equal QtyToDeliver
"COALESCE (SUM(ol.QtyOrdered-ol.QtyDelivered-TargetQty), 0) , " + // Min Qty for this process is equal to TargetQty
" 0 , 0 FROM M_DistributionRunLine rl " + "INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) " + "INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) " + "INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID AND o.DocStatus IN ('DR','IN')) " + "INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) " + "INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID=" + p_M_Warehouse_ID + ") " + "WHERE rl.M_DistributionRun_ID=" + p_M_DistributionRun_ID + " AND rl.IsActive='Y' AND ll.IsActive='Y' AND ol.DatePromised <= " + DB.TO_DATE(p_DatePromised) + " GROUP BY o.M_Shipper_ID , ll.C_BPartner_ID, ol.M_Product_ID";
//+ " BETWEEN "+ DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To)
no = DB.executeUpdate(sql, get_TrxName());
List<MDistributionRunDetail> records = new Query(getCtx(), MDistributionRunDetail.Table_Name, MDistributionRunDetail.COLUMNNAME_M_DistributionRun_ID + "=?", get_TrxName()).setParameters(new Object[] { p_M_DistributionRun_ID }).list();
for (MDistributionRunDetail record : records) {
MDistributionRunLine drl = (MDistributionRunLine) MTable.get(getCtx(), MDistributionRunLine.Table_ID).getPO(record.getM_DistributionRunLine_ID(), get_TrxName());
MProduct product = MProduct.get(getCtx(), record.getM_Product_ID());
BigDecimal ration = record.getRatio();
BigDecimal totalration = getQtyDemand(record.getM_Product_ID());
log.info("Value:" + product.getValue());
log.info("Product:" + product.getName());
log.info("Qty To Deliver:" + record.getRatio());
log.info("Qty Target:" + record.getMinQty());
log.info("Qty Total Available:" + drl.getTotalQty());
log.info("Qty Total Demand:" + totalration);
BigDecimal factor = ration.divide(totalration, 12, BigDecimal.ROUND_HALF_UP);
record.setQty(drl.getTotalQty().multiply(factor));
record.saveEx();
}
log.fine("inserted #" + no);
return no;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class DistributionRun method distributionOrders.
// insertDetails
/**************************************************************************
* Create Orders
* @return true if created
*/
private boolean distributionOrders() {
//The Quantity Available is distribute with respect to Distribution Order Demand
if (p_BasedInDamnd) {
int M_Warehouse_ID = 0;
if (p_M_Warehouse_ID <= 0) {
MOrgInfo oi_source = MOrgInfo.get(getCtx(), m_run.getAD_Org_ID(), get_TrxName());
MWarehouse m_source = MWarehouse.get(getCtx(), oi_source.getM_Warehouse_ID());
if (m_source == null)
throw new AdempiereException("Do not exist Defautl Warehouse Source");
M_Warehouse_ID = m_source.getM_Warehouse_ID();
} else
M_Warehouse_ID = p_M_Warehouse_ID;
// For all lines
for (int i = 0; i < m_details.length; i++) {
MDistributionRunDetail detail = m_details[i];
StringBuffer sql = new StringBuffer("SELECT * FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) ");
//sql.append(" WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND l.M_Warehouse_ID=? AND ol.DatePromised BETWEEN ? AND ? ");
sql.append(" WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND l.M_Warehouse_ID=? AND ol.DatePromised <=?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, detail.getC_BPartner_ID());
pstmt.setInt(2, detail.getM_Product_ID());
pstmt.setInt(3, M_Warehouse_ID);
pstmt.setTimestamp(4, p_DatePromised);
//pstmt.setTimestamp(5, p_DatePromised_To);
rs = pstmt.executeQuery();
while (rs.next()) {
// Create Order Line
MDDOrderLine line = new MDDOrderLine(getCtx(), rs, get_TrxName());
line.setM_Product_ID(detail.getM_Product_ID());
line.setConfirmedQty(line.getTargetQty().add(detail.getActualAllocation()));
if (p_M_Warehouse_ID > 0)
line.setDescription(Msg.translate(getCtx(), "PlannedQty"));
else
line.setDescription(m_run.getName());
line.saveEx();
break;
//addLog(0,null, detail.getActualAllocation(), order.getDocumentNo()
// + ": " + bp.getName() + " - " + product.getName());
}
} catch (Exception e) {
log.log(Level.SEVERE, "doIt - " + sql, e);
return false;
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
return true;
}
// Get Counter Org/BP
int runAD_Org_ID = m_run.getAD_Org_ID();
if (runAD_Org_ID == 0)
runAD_Org_ID = Env.getAD_Org_ID(getCtx());
MOrg runOrg = MOrg.get(getCtx(), runAD_Org_ID);
int runC_BPartner_ID = runOrg.getLinkedC_BPartner_ID(get_TrxName());
boolean counter = // no single Order
!m_run.isCreateSingleOrder() && // Org linked to BP
runC_BPartner_ID > 0 && // PO
!m_docType.isSOTrx();
MBPartner runBPartner = counter ? new MBPartner(getCtx(), runC_BPartner_ID, get_TrxName()) : null;
if (!counter || runBPartner == null || runBPartner.get_ID() != runC_BPartner_ID)
counter = false;
if (counter)
log.info("RunBP=" + runBPartner + " - " + m_docType);
log.info("Single=" + m_run.isCreateSingleOrder() + " - " + m_docType + ",SO=" + m_docType.isSOTrx());
log.fine("Counter=" + counter + ",C_BPartner_ID=" + runC_BPartner_ID + "," + runBPartner);
//
MBPartner bp = null;
MDDOrder singleOrder = null;
MProduct product = null;
MWarehouse m_source = null;
MLocator m_locator = null;
MWarehouse m_target = null;
MLocator m_locator_to = null;
MWarehouse[] ws = null;
MOrgInfo oi_source = MOrgInfo.get(getCtx(), m_run.getAD_Org_ID(), get_TrxName());
m_source = MWarehouse.get(getCtx(), oi_source.getM_Warehouse_ID());
if (m_source == null)
throw new AdempiereException("Do not exist Defautl Warehouse Source");
m_locator = MLocator.getDefault(m_source);
//get the warehouse in transit
ws = MWarehouse.getInTransitForOrg(getCtx(), m_source.getAD_Org_ID());
if (ws == null)
throw new AdempiereException("Warehouse Intransit do not found");
// Consolidated Single Order
if (m_run.isCreateSingleOrder()) {
bp = new MBPartner(getCtx(), m_run.getC_BPartner_ID(), get_TrxName());
if (bp.get_ID() == 0)
throw new IllegalArgumentException("Business Partner not found - C_BPartner_ID=" + m_run.getC_BPartner_ID());
//
if (!p_IsTest) {
singleOrder = new MDDOrder(getCtx(), 0, get_TrxName());
singleOrder.setC_DocType_ID(m_docType.getC_DocType_ID());
singleOrder.setIsSOTrx(m_docType.isSOTrx());
singleOrder.setBPartner(bp);
if (m_run.getC_BPartner_Location_ID() != 0)
singleOrder.setC_BPartner_Location_ID(m_run.getC_BPartner_Location_ID());
singleOrder.setDateOrdered(m_DateOrdered);
singleOrder.setDatePromised(p_DatePromised);
singleOrder.setM_Warehouse_ID(ws[0].getM_Warehouse_ID());
if (!singleOrder.save()) {
log.log(Level.SEVERE, "Order not saved");
return false;
}
m_counter++;
}
}
int lastC_BPartner_ID = 0;
int lastC_BPartner_Location_ID = 0;
MDDOrder order = null;
// For all lines
for (int i = 0; i < m_details.length; i++) {
MDistributionRunDetail detail = m_details[i];
// Create Order Header
if (m_run.isCreateSingleOrder())
order = singleOrder;
else // New Business Partner
if (lastC_BPartner_ID != detail.getC_BPartner_ID() || lastC_BPartner_Location_ID != detail.getC_BPartner_Location_ID()) {
// finish order
order = null;
}
lastC_BPartner_ID = detail.getC_BPartner_ID();
lastC_BPartner_Location_ID = detail.getC_BPartner_Location_ID();
bp = new MBPartner(getCtx(), detail.getC_BPartner_ID(), get_TrxName());
MOrgInfo oi_target = MOrgInfo.get(getCtx(), bp.getAD_OrgBP_ID_Int(), get_TrxName());
m_target = MWarehouse.get(getCtx(), oi_target.getM_Warehouse_ID());
if (m_target == null)
throw new AdempiereException("Do not exist Default Warehouse Target");
m_locator_to = MLocator.getDefault(m_target);
if (m_locator == null || m_locator_to == null) {
throw new AdempiereException("Do not exist default Locator for Warehouses");
}
if (p_ConsolidateDocument) {
String whereClause = "DocStatus IN ('DR','IN') AND AD_Org_ID=" + bp.getAD_OrgBP_ID_Int() + " AND " + MDDOrder.COLUMNNAME_C_BPartner_ID + "=? AND " + MDDOrder.COLUMNNAME_M_Warehouse_ID + "=? AND " + MDDOrder.COLUMNNAME_DatePromised + "<=? ";
order = new Query(getCtx(), MDDOrder.Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised }).setOrderBy(MDDOrder.COLUMNNAME_DatePromised + " DESC").first();
}
// New Order
if (order == null) {
if (!p_IsTest) {
order = new MDDOrder(getCtx(), 0, get_TrxName());
order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int());
order.setC_DocType_ID(m_docType.getC_DocType_ID());
order.setIsSOTrx(m_docType.isSOTrx());
// Counter Doc
if (counter && bp.getAD_OrgBP_ID_Int() > 0) {
log.fine("Counter - From_BPOrg=" + bp.getAD_OrgBP_ID_Int() + "-" + bp + ", To_BP=" + runBPartner);
order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int());
if (ws[0].getM_Warehouse_ID() > 0)
order.setM_Warehouse_ID(ws[0].getM_Warehouse_ID());
order.setBPartner(runBPartner);
} else // normal
{
log.fine("From_Org=" + runAD_Org_ID + ", To_BP=" + bp);
order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int());
order.setBPartner(bp);
if (detail.getC_BPartner_Location_ID() != 0)
order.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID());
}
order.setM_Warehouse_ID(ws[0].getM_Warehouse_ID());
order.setDateOrdered(m_DateOrdered);
order.setDatePromised(p_DatePromised);
order.setIsInDispute(false);
order.setIsInTransit(false);
if (!order.save()) {
log.log(Level.SEVERE, "Order not saved");
return false;
}
}
}
// Line
if (product == null || product.getM_Product_ID() != detail.getM_Product_ID())
product = MProduct.get(getCtx(), detail.getM_Product_ID());
if (p_IsTest) {
addLog(0, null, detail.getActualAllocation(), bp.getName() + " - " + product.getName());
continue;
}
if (p_ConsolidateDocument) {
String sql = "SELECT DD_OrderLine_ID FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND ol.M_Locator_ID=? AND ol.DatePromised <= ?";
int DD_OrderLine_ID = DB.getSQLValueEx(get_TrxName(), sql, new Object[] { detail.getC_BPartner_ID(), product.getM_Product_ID(), m_locator.getM_Locator_ID(), p_DatePromised });
if (DD_OrderLine_ID <= 0) {
MDDOrderLine line = new MDDOrderLine(order);
line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int());
line.setM_Locator_ID(m_locator.getM_Locator_ID());
line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID());
line.setIsInvoiced(false);
line.setProduct(product);
BigDecimal QtyAllocation = detail.getActualAllocation();
if (QtyAllocation == null)
QtyAllocation = Env.ZERO;
line.setQty(QtyAllocation);
line.setQtyEntered(QtyAllocation);
//line.setTargetQty(detail.getActualAllocation());
line.setTargetQty(Env.ZERO);
String Description = "";
if (m_run.getName() != null)
Description = Description.concat(m_run.getName());
line.setDescription(Description + " " + Msg.translate(getCtx(), "Qty") + " = " + QtyAllocation + " ");
//line.setConfirmedQty(QtyAllocation);
line.saveEx();
} else {
MDDOrderLine line = new MDDOrderLine(getCtx(), DD_OrderLine_ID, get_TrxName());
BigDecimal QtyAllocation = detail.getActualAllocation();
if (QtyAllocation == null)
QtyAllocation = Env.ZERO;
String Description = line.getDescription();
if (Description == null)
Description = "";
if (m_run.getName() != null)
Description = Description.concat(m_run.getName());
line.setDescription(Description + " " + Msg.translate(getCtx(), "Qty") + " = " + QtyAllocation + " ");
line.setQty(line.getQtyEntered().add(QtyAllocation));
//line.setConfirmedQty(line.getConfirmedQty().add( QtyAllocation));
line.saveEx();
}
} else {
// Create Order Line
MDDOrderLine line = new MDDOrderLine(order);
if (counter && bp.getAD_OrgBP_ID_Int() > 0)
// don't overwrite counter doc
;
/*else // normal - optionally overwrite
{
line.setC_BPartner_ID(detail.getC_BPartner_ID());
if (detail.getC_BPartner_Location_ID() != 0)
line.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID());
}*/
//
line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int());
line.setM_Locator_ID(m_locator.getM_Locator_ID());
line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID());
line.setIsInvoiced(false);
line.setProduct(product);
line.setQty(detail.getActualAllocation());
line.setQtyEntered(detail.getActualAllocation());
//line.setTargetQty(detail.getActualAllocation());
line.setTargetQty(Env.ZERO);
//line.setConfirmedQty(detail.getActualAllocation());
String Description = "";
if (m_run.getName() != null)
Description = Description.concat(m_run.getName());
line.setDescription(Description + " " + Msg.translate(getCtx(), "Qty") + " = " + detail.getActualAllocation() + " ");
line.saveEx();
}
addLog(0, null, detail.getActualAllocation(), order.getDocumentNo() + ": " + bp.getName() + " - " + product.getName());
}
// finish order
order = null;
return true;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class MRPUtil method getCreatePlant.
/**
* Helper Method : Create Plant (S_Resource_ID)
*/
public static I_S_Resource getCreatePlant(String value, int M_Warehouse_ID, int PlanningHorizon) {
Properties ctx = Env.getCtx();
int AD_Client_ID = Env.getAD_Client_ID(ctx);
String whereClause = MResource.COLUMNNAME_Value + "=? AND AD_Client_ID=?";
MResource r = new Query(ctx, MResource.Table_Name, whereClause, null).setParameters(new Object[] { value, AD_Client_ID }).firstOnly();
if (r == null) {
r = new MResource(ctx, 0, null);
int S_ResourceType_ID = DB.getSQLValueEx(null, "SELECT MIN(S_ResourceType_ID) FROM S_Resource WHERE AD_Client_ID=? AND IsAvailable=?", AD_Client_ID, true);
r.setS_ResourceType_ID(S_ResourceType_ID);
}
r.setValue(value);
r.setName(value);
r.setIsManufacturingResource(true);
r.setManufacturingResourceType(MResource.MANUFACTURINGRESOURCETYPE_Plant);
r.setIsAvailable(true);
r.setM_Warehouse_ID(M_Warehouse_ID);
r.setPlanningHorizon(PlanningHorizon);
r.setPercentUtilization(Env.ONEHUNDRED);
r.saveEx();
return r;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class WAcctViewer method actionButton.
// actionTable
/**
* Action Button
*
* @param button pressed button
* @return ID
* @throws Exception
*/
private int actionButton(Button button) throws Exception {
String keyColumn = button.getName();
log.info(keyColumn);
// String whereClause = ""; // Elaine 2008/07/28
String whereClause = "(IsSummary='N' OR IsSummary IS NULL)";
String lookupColumn = keyColumn;
int record_id = m_data.getButtonRecordID(keyColumn);
if ("Account_ID".equals(keyColumn)) {
lookupColumn = "C_ElementValue_ID";
MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);
if (ase != null)
whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
} else if ("User1_ID".equals(keyColumn)) {
lookupColumn = "C_ElementValue_ID";
MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList1);
if (ase != null)
whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
} else if ("User2_ID".equals(keyColumn)) {
lookupColumn = "C_ElementValue_ID";
MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList2);
if (ase != null)
whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
} else if ("User3_ID".equals(keyColumn)) {
lookupColumn = "C_ElementValue_ID";
MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList3);
if (ase != null)
whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
} else if ("User4_ID".equals(keyColumn)) {
lookupColumn = "C_ElementValue_ID";
MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList4);
if (ase != null)
whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
} else if ("UserElement1_ID".equals(keyColumn)) {
MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X1' ", null).setClient_ID().firstOnly();
String tableName = et.getAD_Column().getAD_Table().getTableName();
String lookupcolumnname = tableName + "_ID";
lookupColumn = lookupcolumnname;
whereClause = "";
} else if ("UserElement2_ID".equals(keyColumn)) {
MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X2' ", null).setClient_ID().firstOnly();
String tableName = et.getAD_Column().getAD_Table().getTableName();
String lookupcolumnname = tableName + "_ID";
lookupColumn = lookupcolumnname;
whereClause = "";
} else if (keyColumn.equals("M_Product_ID")) {
whereClause = "";
} else if (selDocument.isChecked())
whereClause = "";
if (// Record_ID
button == selRecord)
record_id = m_data.Record_ID;
else
record_id = m_data.getButtonRecordID(keyColumn);
String tableName = lookupColumn.substring(0, lookupColumn.length() - 3);
//whereClause = tableName + ".IsSummary='N'" + whereClause; // Elaine 2008/07/28
// Open modal
InfoPanel info = InfoPanel.create(m_data.WindowNo, tableName, lookupColumn, record_id, "", false, whereClause);
if (!info.loadedOK()) {
info.dispose();
info = null;
button.setLabel("");
m_data.whereInfo.put(keyColumn, "");
m_data.buttonRecordID.put(keyColumn, null);
return 0;
}
info.setVisible(true);
AEnv.showWindow(info);
boolean isCancelled = info.isCancelled();
boolean isOK = info.isOk();
Integer key = 0;
if (// Delete the saved info
isCancelled && !isOK) {
key = 0;
if (// Record_ID
button == selRecord)
m_data.Record_ID = key.intValue();
else {
// no query
m_data.whereInfo.put(keyColumn, "");
m_data.buttonRecordID.put(keyColumn, key.intValue());
}
button.setLabel("");
} else if (!isCancelled && isOK) {
// Save for query
// C_Project_ID=100 or ""
String selectSQL = info.getSelectedSQL();
key = (Integer) info.getSelectedKey();
log.config(keyColumn + " - " + key);
if (// Record_ID
button == selRecord)
m_data.Record_ID = key.intValue();
else {
// Add to query
m_data.whereInfo.put(keyColumn, keyColumn + "=" + key.intValue());
m_data.buttonRecordID.put(keyColumn, key.intValue());
}
// Display Selection and resize
button.setLabel(m_data.getButtonText(tableName, lookupColumn, selectSQL));
} else if (// xor: window closed or error - no change
!(isCancelled ^ isOK)) {
// m_data not changed
if (// Record_ID
button == selRecord)
key = m_data.Record_ID = key.intValue();
else
key = m_data.getButtonRecordID(keyColumn);
}
info = null;
return key.intValue();
}
Aggregations