use of org.compiere.model.Query in project adempiere by adempiere.
the class MDDNetworkDistribution method getLines.
// get
/**
* Get Lines
* @return array of lines MDDNetworkDistributionLine
*/
public MDDNetworkDistributionLine[] getLines() {
if (m_lines != null)
return m_lines;
List<MDDNetworkDistributionLine> list = new Query(getCtx(), MDDNetworkDistributionLine.Table_Name, "DD_NetworkDistribution_ID=?", get_TrxName()).setParameters(new Object[] { get_ID() }).setOrderBy("PriorityNo, M_Shipper_ID").list();
m_lines = list.toArray(new MDDNetworkDistributionLine[list.size()]);
return m_lines;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class ForecastEngine method getForecastRules.
/**
* get WM Rules
*
* @param ctx
* @param AD_Client_ID
* @param trxName
* @return Collection of the MForecastRules
*/
public static List<MPPForecastRule> getForecastRules(Properties ctx, int AD_Client_ID, String trxName) {
String whereClause = "";
ArrayList<Object> parameters = new ArrayList<Object>();
if (AD_Client_ID > 0) {
whereClause = MPPForecastRule.COLUMNNAME_AD_Client_ID + "=?";
parameters.add(AD_Client_ID);
} else {
whereClause = null;
}
return new Query(ctx, MPPForecastRule.Table_Name, whereClause, trxName).setOnlyActiveRecords(true).setParameters(parameters).<MPPForecastRule>list();
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class WFactReconcile method resetReconciliation.
// getSelectedRowKeys
private void resetReconciliation() {
log.info("");
//
if (miniTable.getRowCount() == 0)
return;
if (m_noSelected == 0)
return;
int[] rows = miniTable.getSelectedIndices();
if (rows.length == 0)
return;
for (//work backwards and shrink the table as you go
int row = rows.length - 1; //work backwards and shrink the table as you go
row >= 0; //work backwards and shrink the table as you go
row--) {
int factId = miniTable.getRowKey(rows[row]);
MFactReconciliation rec = new Query(Env.getCtx(), MFactReconciliation.Table_Name, "Fact_Acct_ID = ?", null).setParameters(new Object[] { factId }).first();
if (rec == null) {
continue;
}
rec.setMatchCode(null);
rec.saveEx();
((ListModelTable) miniTable.getModel()).remove(rows[row]);
}
calculateSelection();
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class ImportHelper method getAD_ClientByValue.
public static MClient getAD_ClientByValue(Properties ctx, String value, String trxName) throws SQLException {
final String whereClause = I_AD_Client.COLUMNNAME_Value + "= ? ";
MClient result = new Query(ctx, I_AD_Client.Table_Name, whereClause, trxName).setParameters(value).firstOnly();
s_log.info("Client_Value =[" + value + "]");
if (result != null) {
s_log.info("AD_Client_ID = " + result.getAD_Client_ID());
}
return result;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class ExportHelper method generateExportFormat.
/**
* Trifon Generate Export Format process; result =
* <C_Invoice>
* <DocumentNo>101</DocumentNo>
* </C_Invoice>
* @param rootElement
* @param exportFormat
* @param masterPO
* @param masterID
* @param variableMap
* @throws SQLException
* @throws Exception
*/
private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, PO masterPO, int masterID, HashMap<String, Integer> variableMap) throws SQLException, Exception {
Collection<MEXPFormatLine> formatLines = exportFormat.getFormatLines();
@SuppressWarnings("unused") boolean elementHasValue = false;
//for (int i = 0; i < formatLines.length; i++) {
for (MEXPFormatLine formatLine : formatLines) {
if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLElement)) {
// process single XML Attribute
// Create new element
Element newElement = outDocument.createElement(formatLine.getValue());
log.info("Format Line Seach key: " + formatLine.getValue());
if (formatLine.getAD_Column_ID() == 0) {
throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
}
MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
if (column == null) {
throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
}
if (column.isVirtualColumn()) {
log.info("This is Virtual Column!");
} else {
}
//log.info("["+column.getColumnName()+"]");
Object value = masterPO.get_Value(column.getColumnName());
String valueString = null;
if (value != null) {
valueString = value.toString();
} else {
// Could remove this exception and create empty XML Element when column do not have value.
if (formatLine.isMandatory()) {
//throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory"));
}
}
if (column.getAD_Reference_ID() == DisplayType.Date) {
if (valueString != null) {
if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
// "MM/dd/yyyy"
customDateFormat = new SimpleDateFormat(formatLine.getDateFormat());
valueString = customDateFormat.format(Timestamp.valueOf(valueString));
// Add "DateForamt attribute"
newElement.setAttribute("DateFormat", customDateFormat.toPattern());
} else {
newElement.setAttribute("DateFormat", valueString);
}
}
} else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
if (valueString != null) {
if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
// "MM/dd/yyyy"
customDateFormat = new SimpleDateFormat(formatLine.getDateFormat());
valueString = customDateFormat.format(Timestamp.valueOf(valueString));
// Add "DateForamt attribute"
newElement.setAttribute("DateFormat", customDateFormat.toPattern());
} else {
newElement.setAttribute("DateFormat", valueString);
}
}
}
log.info("EXP Field - column=[" + column.getColumnName() + "]; value=" + value);
if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
Text newText = outDocument.createTextNode(valueString);
newElement.appendChild(newText);
rootElement.appendChild(newElement);
elementHasValue = true;
} else {
// Empty field.
if (formatLine.isMandatory()) {
Text newText = outDocument.createTextNode("");
newElement.appendChild(newText);
rootElement.appendChild(newElement);
elementHasValue = true;
}
}
} else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute)) {
// process single XML Attribute
if (formatLine.getAD_Column_ID() == 0) {
throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
}
MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
if (column == null) {
throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
}
if (column.isVirtualColumn()) {
log.info("This is Virtual Column!");
} else {
}
//log.info("["+column.getColumnName()+"]");
Object value = masterPO.get_Value(column.getColumnName());
String valueString = null;
if (value != null) {
valueString = value.toString();
} else {
if (formatLine.isMandatory()) {
throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPFieldMandatory"));
}
}
/* if (column.getAD_Reference_ID() == DisplayType.Date) {
if (valueString != null) {
if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
//Date date = m_customDateFormat.parse ( valueString );
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
} else {
valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
}
}
} else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
if (valueString != null) {
if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
//Date date = m_customDateFormat.parse ( valueString );
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
} else {
valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
}
}
}*/
log.info("EXP Field - column=[" + column.getColumnName() + "]; value=" + value);
if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
rootElement.setAttribute(formatLine.getValue(), valueString);
elementHasValue = true;
} else {
// Empty field.
}
} else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat)) {
// process Embedded Export Format
int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID();
//get from cache
MEXPFormat embeddedFormat = MEXPFormat.get(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName());
MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded);
final StringBuffer whereClause = new StringBuffer(masterPO.get_KeyColumns()[0] + "=?");
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
}
Collection<PO> instances = new Query(masterPO.getCtx(), tableEmbedded.getTableName(), whereClause.toString(), masterPO.get_TrxName()).setClient_ID().setParameters(new Object[] { masterID }).list();
for (PO instance : instances) {
Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) {
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
}
generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
rootElement.appendChild(embeddedElement);
}
} else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat)) {
// process Referenced Export Format
int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID();
//get from cache
MEXPFormat embeddedFormat = MEXPFormat.get(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName());
MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded);
final StringBuffer whereClause = new StringBuffer(tableEmbedded.getTableName() + "_ID =?");
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
}
String columnName = "";
if (formatLine.getAD_Reference_ID() == DisplayType.Table | formatLine.getAD_Reference_ID() == DisplayType.Search) {
MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
columnName = column.getColumnName();
} else {
columnName = tableEmbedded.getTableName() + "_ID";
}
Object value = masterPO.get_Value(columnName);
if (value == null) {
continue;
}
Collection<PO> instances = new Query(masterPO.getCtx(), tableEmbedded.getTableName(), whereClause.toString(), masterPO.get_TrxName()).setClient_ID().setParameters(value).list();
for (PO instance : instances) {
Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) {
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
}
generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
rootElement.appendChild(embeddedElement);
}
} else {
throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPUnknownLineType"));
}
}
}
Aggregations