use of org.compiere.model.MClient in project adempiere by adempiere.
the class Export method doIt.
/**
* Process - Generate Export Format
* @return info
*/
protected String doIt() throws Exception {
outDocument = createNewDocument();
MClient client = MClient.get(getCtx(), p_AD_Client_ID);
log.info(client.toString());
// TODO - get proper Export Format!
int EXP_Format_ID = 1000000;
MTable table = MTable.get(getCtx(), AD_Table_ID);
log.info("Table = " + table);
PO po = table.getPO(p_Record_ID, get_TrxName());
if (po.get_KeyColumns().length > 1 || po.get_KeyColumns().length < 1) {
throw new Exception(Msg.getMsg(getCtx(), "ExportMultiColumnNotSupported"));
}
MEXPFormat exportFormat = new MEXPFormat(getCtx(), EXP_Format_ID, get_TrxName());
StringBuffer sql = new StringBuffer("SELECT * ").append("FROM ").append(table.getTableName()).append(" ").append("WHERE ").append(po.get_KeyColumns()[0]).append("=?");
if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) {
sql.append(" AND ").append(exportFormat.getWhereClause());
}
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, p_Record_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
variableMap.put(TOTAL_SEGMENTS, new Integer(1));
Element rootElement = outDocument.createElement(exportFormat.getValue());
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, p_Record_ID, variableMap);
}
} finally {
try {
if (rs != null)
rs.close();
if (pstmt != null)
pstmt.close();
} catch (SQLException ex) {
/*ignored*/
}
rs = null;
pstmt = null;
}
/* int C_EDIProcessorType_ID = ediProcessor.getC_EDIProcessorType_ID();
X_C_EDIProcessorType ediProcessType = new X_C_EDIProcessorType(getCtx(), C_EDIProcessorType_ID, get_TrxName() );
String javaClass = ediProcessType.getJavaClass();
try {
Class clazz = Class.forName(javaClass);
IOutbandEdiProcessor outbandProcessor = (IOutbandEdiProcessor)clazz.newInstance();
outbandProcessor.process(getCtx(), ediProcessor, result.toString(), "C_Invoice-"+p_Record_ID+".txt", Trx.get( get_TrxName(), false ));
} catch (Exception e) {
result = new StringBuffer( e.toString() );
}
*/
addLog(0, null, null, Msg.getMsg(getCtx(), "ExportProcessResult") + "\n" + outDocument.toString());
return outDocument.toString();
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class CleanUpGW method gardenWorldExists.
private Boolean gardenWorldExists() {
StringBuilder whereClause = new StringBuilder();
// #1
whereClause.append("AD_Client_ID=?");
MClient gwClient = new Query(getCtx(), MClient.Table_Name, whereClause.toString(), null).setParameters(new Object[] { gw_client_id }).first();
if (gwClient != null && gwClient.getName().equals("GardenWorld")) {
return true;
}
return false;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class MCostElementTest method testQuery.
public void testQuery() throws Exception {
X_M_CostElement ce = new X_M_CostElement(getCtx(), 102, null);
MClient client = MClient.get(ce.getCtx());
MCostElement[] retValue5 = MCostElement.getElements(client.getCtx(), null);
assertTrue("getElements returns 8", retValue5.length == 8);
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class ReportEngine method get.
/**************************************************************************
* Get Document Print Engine for Document Type.
* @param ctx context
* @param type document type
* @param Record_ID id
* @param trxName
* @return Report Engine or null
*/
public static ReportEngine get(Properties ctx, int type, int Record_ID, String trxName) {
if (Record_ID < 1) {
log.log(Level.WARNING, "No PrintFormat for Record_ID=" + Record_ID + ", Type=" + type);
return null;
}
// Order - Print Shipment or Invoice
if (type == ORDER) {
int[] what = getDocumentWhat(Record_ID);
if (what != null) {
type = what[0];
Record_ID = what[1];
}
}
// Order
int AD_PrintFormat_ID = 0;
int C_BPartner_ID = 0;
String DocumentNo = null;
int copies = 1;
// Language
MClient client = MClient.get(ctx);
Language language = client.getLanguage();
// Get Document Info
String sql = null;
if (type == CHECK)
sql = // 1
"SELECT bad.Check_PrintFormat_ID," + // 2..5
" c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM C_PaySelectionCheck d" + " INNER JOIN C_PaySelection ps ON (d.C_PaySelection_ID=ps.C_PaySelection_ID)" + " INNER JOIN C_BankAccountDoc bad ON (ps.C_BankAccount_ID=bad.C_BankAccount_ID AND d.PaymentRule=bad.PaymentRule)" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + // info from BankAccount
"WHERE d.C_PaySelectionCheck_ID=?";
else if (type == HR_CHECK)
sql = // 1
"SELECT bad.Check_PrintFormat_ID," + // 2..5
" c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM HR_PaySelectionCheck d" + " INNER JOIN HR_PaySelection ps ON (d.HR_PaySelection_ID=ps.HR_PaySelection_ID)" + " INNER JOIN C_BankAccountDoc bad ON (ps.C_BankAccount_ID=bad.C_BankAccount_ID AND d.PaymentRule=bad.PaymentRule)" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + // info from BankAccount
"WHERE d.HR_PaySelectionCheck_ID=?";
else if (type == DUNNING)
sql = "SELECT dl.Dunning_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,dr.DunningDate " + "FROM C_DunningRunEntry d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " INNER JOIN C_DunningRun dr ON (d.C_DunningRun_ID=dr.C_DunningRun_ID)" + " INNER JOIN C_DunningLevel dl ON (dl.C_DunningLevel_ID=d.C_DunningLevel_ID) " + // info from Dunning
"WHERE d.C_DunningRunEntry_ID=?";
else if (type == REMITTANCE)
sql = "SELECT pf.Remittance_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM C_PaySelectionCheck d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + // info from PrintForm
"WHERE d.C_PaySelectionCheck_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
else if (type == HR_REMITTANCE)
sql = "SELECT pf.Remittance_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.DocumentNo " + "FROM HR_PaySelectionCheck d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + // info from PrintForm
"WHERE d.HR_PaySelectionCheck_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
else if (type == PROJECT)
sql = "SELECT pf.Project_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,d.Value " + "FROM C_Project d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " LEFT OUTER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + // info from PrintForm
"WHERE d.C_Project_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
else if (type == MANUFACTURING_ORDER)
sql = "SELECT pf.Manuf_Order_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language, 0 , d.DocumentNo " + "FROM PP_Order d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " LEFT OUTER JOIN AD_User u ON (u.AD_User_ID=d.Planner_ID)" + " LEFT OUTER JOIN C_BPartner bp ON (u.C_BPartner_ID=bp.C_BPartner_ID) " + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + // info from PrintForm
"WHERE d.PP_Order_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
else if (type == DISTRIBUTION_ORDER)
sql = "SELECT pf.Distrib_Order_PrintFormat_ID," + " c.IsMultiLingualDocument,bp.AD_Language, bp.C_BPartner_ID , d.DocumentNo " + "FROM DD_Order d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " LEFT OUTER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) " + // info from PrintForm
"WHERE d.DD_Order_ID=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) ORDER BY pf.AD_Org_ID DESC";
else if (type == RFQ)
sql = "SELECT COALESCE(t.AD_PrintFormat_ID, pf.AD_PrintFormat_ID)," + " c.IsMultiLingualDocument,bp.AD_Language,bp.C_BPartner_ID,rr.Name " + "FROM C_RfQResponse rr" + " INNER JOIN C_RfQ r ON (rr.C_RfQ_ID=r.C_RfQ_ID)" + " INNER JOIN C_RfQ_Topic t ON (r.C_RfQ_Topic_ID=t.C_RfQ_Topic_ID)" + " INNER JOIN AD_Client c ON (rr.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (rr.C_BPartner_ID=bp.C_BPartner_ID)," + " AD_PrintFormat pf " + "WHERE pf.AD_Client_ID IN (0,rr.AD_Client_ID)" + // from RfQ PrintFormat
" AND pf.AD_Table_ID=725 AND pf.IsTableBased='N'" + // Info from RfQTopic
" AND rr.C_RfQResponse_ID=? " + "ORDER BY t.AD_PrintFormat_ID, pf.AD_Client_ID DESC, pf.AD_Org_ID DESC";
else // Fix [2574162] Priority to choose invoice print format not working
if (type == ORDER || type == INVOICE)
sql = // 1..2
"SELECT pf.Order_PrintFormat_ID,pf.Shipment_PrintFormat_ID," + // Prio: 1. BPartner 2. DocType, 3. PrintFormat (Org) // see InvoicePrint
" COALESCE (bp.Invoice_PrintFormat_ID,dt.AD_PrintFormat_ID,pf.Invoice_PrintFormat_ID)," + // 3
" pf.Project_PrintFormat_ID, pf.Remittance_PrintFormat_ID," + // 4..5
" c.IsMultiLingualDocument, bp.AD_Language," + // 6..7
" COALESCE(dt.DocumentCopies,0)+COALESCE(bp.DocumentCopies,1), " + // 8
" dt.AD_PrintFormat_ID,bp.C_BPartner_ID,d.DocumentNo " + // 9..11
"FROM " + DOC_BASETABLES[type] + " d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " LEFT OUTER JOIN C_DocType dt ON ((d.C_DocType_ID>0 AND d.C_DocType_ID=dt.C_DocType_ID) OR (d.C_DocType_ID=0 AND d.C_DocTypeTarget_ID=dt.C_DocType_ID)) " + "WHERE d." + DOC_IDS[type] + // info from PrintForm
"=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) " + "ORDER BY pf.AD_Org_ID DESC";
else
// Get PrintFormat from Org or 0 of document client
sql = // 1..2
"SELECT pf.Order_PrintFormat_ID,pf.Shipment_PrintFormat_ID," + // Prio: 1. BPartner 2. DocType, 3. PrintFormat (Org) // see InvoicePrint
" COALESCE (bp.Invoice_PrintFormat_ID,dt.AD_PrintFormat_ID,pf.Invoice_PrintFormat_ID)," + // 3
" pf.Project_PrintFormat_ID, pf.Remittance_PrintFormat_ID," + // 4..5
" c.IsMultiLingualDocument, bp.AD_Language," + // 6..7
" COALESCE(dt.DocumentCopies,0)+COALESCE(bp.DocumentCopies,1), " + // 8
" dt.AD_PrintFormat_ID,bp.C_BPartner_ID,d.DocumentNo, " + // 9..11
" pf.Manuf_Order_PrintFormat_ID, pf.Distrib_Order_PrintFormat_ID " + // 12..13
"FROM " + DOC_BASETABLES[type] + " d" + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " LEFT OUTER JOIN C_DocType dt ON (d.C_DocType_ID=dt.C_DocType_ID) " + "WHERE d." + DOC_IDS[type] + // info from PrintForm
"=?" + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) " + "ORDER BY pf.AD_Org_ID DESC";
//
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, Record_ID);
rs = pstmt.executeQuery();
if (// first record only
rs.next()) {
if (type == CHECK || type == HR_CHECK || type == DUNNING || type == REMITTANCE || type == HR_REMITTANCE || type == PROJECT || type == RFQ || type == MANUFACTURING_ORDER || type == DISTRIBUTION_ORDER) {
AD_PrintFormat_ID = rs.getInt(1);
copies = 1;
// Set Language when enabled
String AD_Language = rs.getString(3);
if (// && "Y".equals(rs.getString(2))) // IsMultiLingualDocument
AD_Language != null)
language = Language.getLanguage(AD_Language);
C_BPartner_ID = rs.getInt(4);
if (type == DUNNING) {
Timestamp ts = rs.getTimestamp(5);
DocumentNo = ts.toString();
} else
DocumentNo = rs.getString(5);
} else {
// Set PrintFormat
AD_PrintFormat_ID = rs.getInt(type + 1);
if (// C_DocType.AD_PrintFormat_ID
type != INVOICE && rs.getInt(9) != 0)
AD_PrintFormat_ID = rs.getInt(9);
copies = rs.getInt(8);
// Set Language when enabled
String AD_Language = rs.getString(7);
if (// && "Y".equals(rs.getString(6))) // IsMultiLingualDocument
AD_Language != null)
language = Language.getLanguage(AD_Language);
C_BPartner_ID = rs.getInt(10);
DocumentNo = rs.getString(11);
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "Record_ID=" + Record_ID + ", SQL=" + sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (AD_PrintFormat_ID == 0) {
log.log(Level.SEVERE, "No PrintFormat found for Type=" + type + ", Record_ID=" + Record_ID);
return null;
}
// Get Format & Data
MPrintFormat format = MPrintFormat.get(ctx, AD_PrintFormat_ID, false);
// BP Language if Multi-Lingual
format.setLanguage(language);
// if (!Env.isBaseLanguage(language, DOC_TABLES[type]))
format.setTranslationLanguage(language);
// query
MQuery query = new MQuery(format.getAD_Table_ID());
query.addRestriction(DOC_IDS[type], MQuery.EQUAL, Record_ID);
//
if (DocumentNo == null || DocumentNo.length() == 0)
DocumentNo = "DocPrint";
PrintInfo info = new PrintInfo(DocumentNo, DOC_TABLE_ID[type], Record_ID, C_BPartner_ID);
info.setCopies(copies);
// true prints "Copy" on second
info.setDocumentCopy(false);
info.setPrinterName(format.getPrinterName());
// Engine
ReportEngine re = new ReportEngine(ctx, format, query, info, trxName);
return re;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class MPrintFormat method createFromTable.
// createFromTable
/**
* Create MPrintFormat for Table
* @param ctx context
* @param AD_Table_ID table
* @param AD_PrintFormat_ID 0 or existing PrintFormat
* @return print format
*/
public static MPrintFormat createFromTable(Properties ctx, int AD_Table_ID, int AD_PrintFormat_ID) {
MClient company = MClient.get(ctx);
s_log.info("AD_Table_ID=" + AD_Table_ID + " - AD_Client_ID=" + company.get_ID());
MPrintFormat pf = new MPrintFormat(ctx, AD_PrintFormat_ID, null);
pf.setAD_Table_ID(AD_Table_ID);
// Get Info
String sql = // 1
"SELECT TableName," + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Table_ID=t.AD_Table_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + // 3
" COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID," + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID " + "FROM AD_Table t, AD_Client c" + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y')," + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp " + // #1/2
"WHERE t.AD_Table_ID=? AND c.AD_Client_ID=?" + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'";
boolean error = true;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
pstmt.setInt(2, company.get_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
// Name
String TableName = rs.getString(1);
String ColumnName = TableName + "_ID";
String s = ColumnName;
if (!ColumnName.equals("T_Report_ID")) {
s = Msg.translate(ctx, ColumnName);
if (// not found
ColumnName.equals(s))
s = Msg.translate(ctx, TableName);
}
int count = rs.getInt(2);
if (count > 0)
s += "_" + (count + 1);
pf.setName(company.getValue() + " -> " + s);
//
pf.setAD_PrintColor_ID(rs.getInt(3));
pf.setAD_PrintFont_ID(rs.getInt(4));
pf.setAD_PrintPaper_ID(rs.getInt(5));
//
error = false;
} else
s_log.log(Level.SEVERE, "No info found " + AD_Table_ID);
} catch (SQLException e) {
s_log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (error)
return null;
// Save & complete
if (!pf.save())
return null;
// pf.dump();
pf.setItems(createItems(ctx, pf));
//
return pf;
}
Aggregations