Search in sources :

Example 36 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class PP_Product_BOM_Check method raiseError.

// doIt
private void raiseError(String string, String hint) throws Exception {
    DB.rollback(false, get_TrxName());
    // parent
    MProduct xp = new MProduct(getCtx(), p_Record_ID, null);
    // set BOM not verified
    xp.setIsVerified(false);
    xp.saveEx();
    String msg = string;
    ValueNamePair pp = CLogger.retrieveError();
    if (pp != null)
        msg = pp.getName() + " - ";
    msg += hint;
    throw new AdempiereUserError(msg);
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereUserError(org.compiere.util.AdempiereUserError) ValueNamePair(org.compiere.util.ValueNamePair)

Example 37 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class ClientAcctProcessor method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_AcctSchema_ID=" + p_C_AcctSchema_ID + ", AD_Table_ID=" + p_AD_Table_ID);
    if (!MClient.isClientAccounting())
        throw new AdempiereUserError(Msg.getMsg(getCtx(), "ClientAccountingNotEnabled"));
    m_client = MClient.get(getCtx(), getAD_Client_ID());
    if (p_C_AcctSchema_ID == 0)
        m_ass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID());
    else
        //	only specific accounting schema
        m_ass = new MAcctSchema[] { new MAcctSchema(getCtx(), p_C_AcctSchema_ID, get_TrxName()) };
    postSession();
    addLog(m_summary.toString());
    return "@OK@";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError)

Example 38 with AdempiereUserError

use of org.compiere.util.AdempiereUserError 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();
}
Also used : MCommissionLine(org.compiere.model.MCommissionLine) AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) Timestamp(java.sql.Timestamp) MCommission(org.compiere.model.MCommission) SimpleDateFormat(java.text.SimpleDateFormat) MCommissionAmt(org.compiere.model.MCommissionAmt) MUser(org.compiere.model.MUser) MCommissionRun(org.compiere.model.MCommissionRun)

Example 39 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class ColumnEncryption method doIt.

// prepare
/**
	 * Process
	 * 
	 * @return info
	 * @throws Exception
	 */
protected String doIt() throws Exception {
    log.info("AD_Column_ID=" + p_AD_Column_ID + ", IsEncrypted=" + p_IsEncrypted + ", ChangeSetting=" + p_ChangeSetting + ", MaxLength=" + p_MaxLength);
    MColumn column = new MColumn(getCtx(), p_AD_Column_ID, get_TrxName());
    if (column.get_ID() == 0 || column.get_ID() != p_AD_Column_ID)
        throw new AdempiereUserError("@NotFound@ @AD_Column_ID@ - " + p_AD_Column_ID);
    //
    String columnName = column.getColumnName();
    int dt = column.getAD_Reference_ID();
    // Can it be enabled?
    if (column.isKey() || column.isParent() || column.isStandardColumn() || column.isVirtualColumn() || column.isIdentifier() || column.isTranslated() || DisplayType.isLookup(dt) || DisplayType.isLOB(dt) || "DocumentNo".equalsIgnoreCase(column.getColumnName()) || "Value".equalsIgnoreCase(column.getColumnName()) || "Name".equalsIgnoreCase(column.getColumnName())) {
        if (column.isEncrypted()) {
            column.setIsEncrypted(false);
            column.saveEx();
        }
        return columnName + ": cannot be encrypted";
    }
    // Start
    addLog(0, null, null, "Encryption Class = " + SecureEngine.getClassName());
    boolean error = false;
    // Test Value
    if (p_TestValue != null && p_TestValue.length() > 0) {
        String encString = SecureEngine.encrypt(p_TestValue);
        addLog(0, null, null, "Encrypted Test Value=" + encString);
        String clearString = SecureEngine.decrypt(encString);
        if (p_TestValue.equals(clearString))
            addLog(0, null, null, "Decrypted=" + clearString + " (same as test value)");
        else {
            addLog(0, null, null, "Decrypted=" + clearString + " (NOT the same as test value - check algorithm)");
            error = true;
        }
        int encLength = encString.length();
        addLog(0, null, null, "Test Length=" + p_TestValue.length() + " -> " + encLength);
        if (encLength <= column.getFieldLength())
            addLog(0, null, null, "Encrypted Length (" + encLength + ") fits into field (" + column.getFieldLength() + ")");
        else {
            addLog(0, null, null, "Encrypted Length (" + encLength + ") does NOT fit into field (" + column.getFieldLength() + ") - resize field");
            error = true;
        }
    }
    // Length Test
    if (p_MaxLength != 0) {
        String testClear = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        while (testClear.length() < p_MaxLength) testClear += testClear;
        testClear = testClear.substring(0, p_MaxLength);
        log.config("Test=" + testClear + " (" + p_MaxLength + ")");
        //
        String encString = SecureEngine.encrypt(testClear);
        int encLength = encString.length();
        addLog(0, null, null, "Test Max Length=" + testClear.length() + " -> " + encLength);
        if (encLength <= column.getFieldLength())
            addLog(0, null, null, "Encrypted Max Length (" + encLength + ") fits into field (" + column.getFieldLength() + ")");
        else {
            addLog(0, null, null, "Encrypted Max Length (" + encLength + ") does NOT fit into field (" + column.getFieldLength() + ") - resize field");
            error = true;
        }
    }
    // settings resize the physical column and encrypt all its contents.
    if (p_IsEncrypted && p_ChangeSetting) {
        // and exit.
        if (column.isEncrypted()) {
            log.severe("EncryptError: Column already encrypted.");
            throw new Exception();
        }
        // Init the transaction and setup the connection.
        m_trx = Trx.get(get_TrxName(), true);
        if ((m_conn = m_trx.getConnection()) == null) {
            log.warning("EncryptError: No connections available");
            throw new Exception();
        }
        m_conn.setAutoCommit(false);
        int columnID = column.get_ID();
        MTable table = MTable.get(getCtx(), column.getAD_Table_ID());
        String tableName = table.getTableName();
        // Check if the encryption exceeds the current length.
        int oldLength = column.getFieldLength();
        int newLength = encryptedColumnLength(oldLength);
        if (newLength > oldLength)
            if (changeFieldLength(columnID, columnName, newLength, tableName) == -1) {
                log.warning("EncryptError [ChangeFieldLength]: " + "ColumnID=" + columnID + ", NewLength=" + newLength);
                throw new Exception();
            }
        // Encrypt column contents.
        if (encryptColumnContents(columnName, column.getAD_Table_ID()) == -1) {
            log.warning("EncryptError: No records encrypted.");
            throw new Exception();
        }
        if (p_IsEncrypted != column.isEncrypted()) {
            if (error || !p_ChangeSetting)
                addLog(0, null, null, "Encryption NOT changed - Encryption=" + column.isEncrypted());
            else {
                column.setIsEncrypted(p_IsEncrypted);
                if (column.save())
                    addLog(0, null, null, "Encryption CHANGED - Encryption=" + column.isEncrypted());
                else
                    addLog(0, null, null, "Save Error");
            }
        }
    }
    return "Encryption=" + column.isEncrypted();
}
Also used : MColumn(org.compiere.model.MColumn) AdempiereUserError(org.compiere.util.AdempiereUserError) MTable(org.compiere.model.MTable)

Example 40 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class BankStatementPayment method createPayment.

//	doIt
/**
	 * 	Create Payment for Import
	 *	@param ibs import bank statement
	 *	@return Message
	 *  @throws Exception if not successful
	 */
private String createPayment(X_I_BankStatement ibs) throws Exception {
    if (ibs == null || ibs.getC_Payment_ID() != 0)
        return "--";
    log.fine(ibs.toString());
    if (ibs.getC_Invoice_ID() == 0 && ibs.getC_BPartner_ID() == 0)
        throw new AdempiereUserError("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@");
    if (ibs.getC_BankAccount_ID() == 0)
        throw new AdempiereUserError("@NotFound@ @C_BankAccount_ID@");
    //
    MPayment payment = createPayment(ibs.getC_Invoice_ID(), ibs.getC_BPartner_ID(), ibs.getC_Currency_ID(), ibs.getStmtAmt(), ibs.getTrxAmt(), ibs.getC_BankAccount_ID(), ibs.getStatementLineDate() == null ? ibs.getStatementDate() : ibs.getStatementLineDate(), ibs.getDateAcct(), ibs.getDescription(), ibs.getAD_Org_ID());
    if (payment == null)
        throw new AdempiereSystemError("Could not create Payment");
    ibs.setC_Payment_ID(payment.getC_Payment_ID());
    ibs.setC_Currency_ID(payment.getC_Currency_ID());
    ibs.setTrxAmt(payment.getPayAmt(true));
    ibs.saveEx();
    //
    String retString = "@C_Payment_ID@ = " + payment.getDocumentNo();
    if (payment.getOverUnderAmt().signum() != 0)
        retString += " - @OverUnderAmt@=" + payment.getOverUnderAmt();
    return retString;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MPayment(org.compiere.model.MPayment)

Aggregations

AdempiereUserError (org.compiere.util.AdempiereUserError)62 PreparedStatement (java.sql.PreparedStatement)9 BigDecimal (java.math.BigDecimal)8 Timestamp (java.sql.Timestamp)8 AdempiereSystemError (org.compiere.util.AdempiereSystemError)8 ResultSet (java.sql.ResultSet)7 MBPartner (org.compiere.model.MBPartner)7 MClient (org.compiere.model.MClient)5 MWarehouse (org.compiere.model.MWarehouse)5 MProduct (org.compiere.model.MProduct)4 ValueNamePair (org.compiere.util.ValueNamePair)4 MUser (org.compiere.model.MUser)3 X_T_Replenish (org.compiere.model.X_T_Replenish)3 MPrintFormat (org.compiere.print.MPrintFormat)3 File (java.io.File)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MBPartnerLocation (org.compiere.model.MBPartnerLocation)2 MColumn (org.compiere.model.MColumn)2 MCommission (org.compiere.model.MCommission)2