use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class TableCreateColumns method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
if (p_AD_Table_ID == 0)
throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID);
log.info("EntityType=" + p_EntityType + ", AllTables=" + p_AllTables + ", AD_Table_ID=" + p_AD_Table_ID);
//
Connection conn = null;
try {
conn = DB.getConnectionRO();
AdempiereDatabase db = DB.getDatabase();
DatabaseMetaData md = conn.getMetaData();
String catalog = db.getCatalog();
String schema = db.getSchema();
if (p_AllTables)
addTable(md, catalog, schema);
else {
MTable table = new MTable(getCtx(), p_AD_Table_ID, get_TrxName());
if (table == null || table.get_ID() == 0)
throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID);
log.info(table.getTableName() + ", EntityType=" + p_EntityType);
String tableName = table.getTableName();
if (DB.isOracle())
tableName = tableName.toUpperCase();
// globalqss 2005-10-24
if (DB.isPostgreSQL())
tableName = tableName.toLowerCase();
// end globalqss 2005-10-24
ResultSet rs = md.getColumns(catalog, schema, tableName, null);
addTableColumn(rs, table);
}
return "#" + m_count;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class RequestInvoice method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("R_RequestType_ID=" + p_R_RequestType_ID + ", R_Group_ID=" + p_R_Group_ID + ", R_Category_ID=" + p_R_Category_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + ", p_M_Product_ID=" + p_M_Product_ID);
MRequestType type = MRequestType.get(getCtx(), p_R_RequestType_ID);
if (type.get_ID() == 0)
throw new AdempiereSystemError("@R_RequestType_ID@ @NotFound@ " + p_R_RequestType_ID);
if (!type.isInvoiced())
throw new AdempiereSystemError("@R_RequestType_ID@ <> @IsInvoiced@");
String sql = "SELECT * FROM R_Request r" + " INNER JOIN R_Status s ON (r.R_Status_ID=s.R_Status_ID) " + "WHERE s.IsClosed='Y'" + " AND r.R_RequestType_ID=?";
// "WHERE ru.R_Request_ID=r.R_Request_ID AND NVL(C_InvoiceLine_ID,0)=0";
if (p_R_Group_ID != 0)
sql += " AND r.R_Group_ID=?";
if (p_R_Category_ID != 0)
sql += " AND r.R_Category_ID=?";
if (p_C_BPartner_ID != 0)
sql += " AND r.C_BPartner_ID=?";
sql += " AND r.IsInvoiced='Y' " + "ORDER BY C_BPartner_ID";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
int index = 1;
pstmt.setInt(index++, p_R_RequestType_ID);
if (p_R_Group_ID != 0)
pstmt.setInt(index++, p_R_Group_ID);
if (p_R_Category_ID != 0)
pstmt.setInt(index++, p_R_Category_ID);
if (p_C_BPartner_ID != 0)
pstmt.setInt(index++, p_C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
int oldC_BPartner_ID = 0;
while (rs.next()) {
MRequest request = new MRequest(getCtx(), rs, get_TrxName());
if (!request.isInvoiced())
continue;
if (oldC_BPartner_ID != request.getC_BPartner_ID())
invoiceDone();
if (m_invoice == null) {
invoiceNew(request);
oldC_BPartner_ID = request.getC_BPartner_ID();
}
invoiceLine(request);
}
invoiceDone();
//
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
// R_Category_ID
return null;
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class Find method getSubCategoryWhereClause.
/**
* Returns a sql where string with the given category id and all of its subcategory ids.
* It is used as restriction in MQuery.
* @param productCategoryId
* @return
*/
private String getSubCategoryWhereClause(int productCategoryId) {
//if a node with this id is found later in the search we have a loop in the tree
int subTreeRootParentId = 0;
String retString = " M_Product_Category_ID IN (";
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
Statement stmt = null;
ResultSet rs = null;
try {
stmt = DB.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
if (rs.getInt(1) == productCategoryId) {
subTreeRootParentId = rs.getInt(2);
}
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
}
retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId);
retString += ") ";
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
retString = "";
} catch (AdempiereSystemError e) {
log.log(Level.SEVERE, sql, e);
retString = "";
} finally {
DB.close(rs, stmt);
rs = null;
stmt = null;
}
return retString;
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class HouseKeeping method doIt.
//prepare
protected String doIt() throws Exception {
X_AD_HouseKeeping houseKeeping = new X_AD_HouseKeeping(getCtx(), p_AD_HouseKeeping_ID, get_TrxName());
int tableID = houseKeeping.getAD_Table_ID();
MTable table = new MTable(getCtx(), tableID, get_TrxName());
String tableName = table.getTableName();
String whereClause = houseKeeping.getWhereClause();
int noins = 0;
int noexp = 0;
int nodel = 0;
if (houseKeeping.isSaveInHistoric()) {
String sql = "INSERT INTO hst_" + tableName + " SELECT * FROM " + tableName;
if (whereClause != null && whereClause.length() > 0)
sql = sql + " WHERE " + whereClause;
noins = DB.executeUpdate(sql, get_TrxName());
if (noins == -1)
throw new AdempiereSystemError("Cannot insert into hst_" + tableName);
addLog("@Inserted@ " + noins);
}
//saveInHistoric
Date date = new Date();
if (houseKeeping.isExportXMLBackup()) {
String pathFile = houseKeeping.getBackupFolder();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = dateFormat.format(date);
FileWriter file = new FileWriter(pathFile + File.separator + tableName + dateString + ".xml");
String sql = "SELECT * FROM " + tableName;
if (whereClause != null && whereClause.length() > 0)
sql = sql + " WHERE " + whereClause;
PreparedStatement pstmt = null;
ResultSet rs = null;
StringBuffer linexml = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
rs = pstmt.executeQuery();
while (rs.next()) {
GenericPO po = new GenericPO(tableName, getCtx(), rs, get_TrxName());
linexml = po.get_xmlString(linexml);
noexp++;
}
if (linexml != null)
file.write(linexml.toString());
file.close();
} catch (Exception e) {
throw e;
} finally {
DB.close(rs, pstmt);
pstmt = null;
rs = null;
}
addLog("@Exported@ " + noexp);
}
//XmlExport
String sql = "DELETE FROM " + tableName;
if (whereClause != null && whereClause.length() > 0)
sql = sql + " WHERE " + whereClause;
nodel = DB.executeUpdate(sql, get_TrxName());
if (nodel == -1)
throw new AdempiereSystemError("Cannot delete from " + tableName);
Timestamp time = new Timestamp(date.getTime());
houseKeeping.setLastRun(time);
houseKeeping.setLastDeleted(nodel);
houseKeeping.saveEx();
addLog("@Deleted@ " + nodel);
String msg = Msg.translate(getCtx(), tableName + "_ID") + " #" + nodel;
return msg;
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class CommissionCalc method doIt.
// prepare
/**
* Perform process.
* @return Message (text with variables)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("C_Commission_ID=" + getRecord_ID() + ", StartDate=" + p_StartDate);
if (p_StartDate == null)
p_StartDate = new Timestamp(System.currentTimeMillis());
m_com = new MCommission(getCtx(), getRecord_ID(), get_TrxName());
if (m_com.get_ID() == 0)
throw new AdempiereUserError("No Commission");
// Create Commission
MCommissionRun comRun = new MCommissionRun(m_com);
setStartEndDate();
comRun.setStartDate(p_StartDate);
// 01-Jan-2000 - 31-Jan-2001 - USD
SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date);
String description = format.format(p_StartDate) + " - " + format.format(m_EndDate) + " - " + MCurrency.getISO_Code(getCtx(), m_com.getC_Currency_ID());
comRun.setDescription(description);
if (!comRun.save())
throw new AdempiereSystemError("Could not save Commission Run");
MCommissionLine[] lines = m_com.getLines();
for (int i = 0; i < lines.length; i++) {
// Amt for Line - Updated By Trigger
MCommissionAmt comAmt = new MCommissionAmt(comRun, lines[i].getC_CommissionLine_ID());
if (!comAmt.save())
throw new AdempiereSystemError("Could not save Commission Amt");
//
StringBuffer sql = new StringBuffer();
if (MCommission.DOCBASISTYPE_Receipt.equals(m_com.getDocBasisType())) {
if (m_com.isListDetails()) {
sql.append("SELECT h.C_Currency_ID, (l.LineNetAmt*al.Amount/h.GrandTotal) AS Amt," + " (l.QtyInvoiced*al.Amount/h.GrandTotal) AS Qty," + " NULL, l.C_InvoiceLine_ID, p.DocumentNo||'_'||h.DocumentNo," + " COALESCE(prd.Value,l.Description), h.DateInvoiced " + "FROM C_Payment p" + " INNER JOIN C_AllocationLine al ON (p.C_Payment_ID=al.C_Payment_ID)" + " INNER JOIN C_Invoice h ON (al.C_Invoice_ID = h.C_Invoice_ID)" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID) " + " LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) " + "WHERE p.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND p.AD_Client_ID = ?" + " AND p.DateTrx BETWEEN ? AND ?");
} else {
sql.append("SELECT h.C_Currency_ID, SUM(l.LineNetAmt*al.Amount/h.GrandTotal) AS Amt," + " SUM(l.QtyInvoiced*al.Amount/h.GrandTotal) AS Qty," + " NULL, NULL, NULL, NULL, MAX(h.DateInvoiced) " + "FROM C_Payment p" + " INNER JOIN C_AllocationLine al ON (p.C_Payment_ID=al.C_Payment_ID)" + " INNER JOIN C_Invoice h ON (al.C_Invoice_ID = h.C_Invoice_ID)" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID) " + "WHERE p.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND p.AD_Client_ID = ?" + " AND p.DateTrx BETWEEN ? AND ?");
}
} else if (MCommission.DOCBASISTYPE_Order.equals(m_com.getDocBasisType())) {
if (m_com.isListDetails()) {
sql.append("SELECT h.C_Currency_ID, l.LineNetAmt, l.QtyOrdered, " + "l.C_OrderLine_ID, NULL, h.DocumentNo," + " COALESCE(prd.Value,l.Description),h.DateOrdered " + "FROM C_Order h" + " INNER JOIN C_OrderLine l ON (h.C_Order_ID = l.C_Order_ID)" + " LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) " + "WHERE h.DocStatus IN ('CL','CO')" + " AND h.IsSOTrx='Y'" + " AND h.AD_Client_ID = ?" + " AND h.DateOrdered BETWEEN ? AND ?");
} else {
sql.append("SELECT h.C_Currency_ID, SUM(l.LineNetAmt) AS Amt," + " SUM(l.QtyOrdered) AS Qty, " + "NULL, NULL, NULL, NULL, MAX(h.DateOrdered) " + "FROM C_Order h" + " INNER JOIN C_OrderLine l ON (h.C_Order_ID = l.C_Order_ID) " + "WHERE h.DocStatus IN ('CL','CO')" + " AND h.IsSOTrx='Y'" + " AND h.AD_Client_ID = ?" + " AND h.DateOrdered BETWEEN ? AND ?");
}
} else // Invoice Basis
{
if (m_com.isListDetails()) {
sql.append("SELECT h.C_Currency_ID, l.LineNetAmt, l.QtyInvoiced, " + "NULL, l.C_InvoiceLine_ID, h.DocumentNo," + " COALESCE(prd.Value,l.Description),h.DateInvoiced " + "FROM C_Invoice h" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID)" + " LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) " + "WHERE h.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND h.AD_Client_ID = ?" + " AND h.DateInvoiced BETWEEN ? AND ?");
} else {
sql.append("SELECT h.C_Currency_ID, SUM(l.LineNetAmt) AS Amt," + " SUM(l.QtyInvoiced) AS Qty, " + "NULL, NULL, NULL, NULL, MAX(h.DateInvoiced) " + "FROM C_Invoice h" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID) " + "WHERE h.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND h.AD_Client_ID = ?" + " AND h.DateInvoiced BETWEEN ? AND ?");
}
}
// CommissionOrders/Invoices
if (lines[i].isCommissionOrders()) {
MUser[] users = MUser.getOfBPartner(getCtx(), m_com.getC_BPartner_ID(), get_TrxName());
if (users == null || users.length == 0)
throw new AdempiereUserError("Commission Business Partner has no Users/Contact");
if (users.length == 1) {
int SalesRep_ID = users[0].getAD_User_ID();
sql.append(" AND h.SalesRep_ID=").append(SalesRep_ID);
} else {
log.warning("Not 1 User/Contact for C_BPartner_ID=" + m_com.getC_BPartner_ID() + " but " + users.length);
sql.append(" AND h.SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=").append(m_com.getC_BPartner_ID()).append(")");
}
}
// Organization
if (lines[i].getOrg_ID() != 0)
sql.append(" AND h.AD_Org_ID=").append(lines[i].getOrg_ID());
// BPartner
if (lines[i].getC_BPartner_ID() != 0)
sql.append(" AND h.C_BPartner_ID=").append(lines[i].getC_BPartner_ID());
// BPartner Group
if (lines[i].getC_BP_Group_ID() != 0)
sql.append(" AND h.C_BPartner_ID IN " + "(SELECT C_BPartner_ID FROM C_BPartner WHERE C_BP_Group_ID=").append(lines[i].getC_BP_Group_ID()).append(")");
// Sales Region
if (lines[i].getC_SalesRegion_ID() != 0)
sql.append(" AND h.C_BPartner_Location_ID IN " + "(SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_SalesRegion_ID=").append(lines[i].getC_SalesRegion_ID()).append(")");
// Product
if (lines[i].getM_Product_ID() != 0)
sql.append(" AND l.M_Product_ID=").append(lines[i].getM_Product_ID());
// Product Category
if (lines[i].getM_Product_Category_ID() != 0)
sql.append(" AND l.M_Product_ID IN " + "(SELECT M_Product_ID FROM M_Product WHERE M_Product_Category_ID=").append(lines[i].getM_Product_Category_ID()).append(")");
// Payment Rule
if (lines[i].getPaymentRule() != null)
sql.append(" AND h.PaymentRule='").append(lines[i].getPaymentRule()).append("'");
// Grouping
if (!m_com.isListDetails())
sql.append(" GROUP BY h.C_Currency_ID");
//
log.fine("Line=" + lines[i].getLine() + " - " + sql);
//
createDetail(sql.toString(), comAmt);
comAmt.calculateCommission();
comAmt.saveEx();
}
// for all commission lines
// comRun.updateFromAmt();
// comRun.saveEx();
// Save Last Run
m_com.setDateLastRun(p_StartDate);
m_com.saveEx();
return "@C_CommissionRun_ID@ = " + comRun.getDocumentNo() + " - " + comRun.getDescription();
}
Aggregations