Search in sources :

Example 11 with AdempiereUserError

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

the class PaySelectionCreateCheck method createCheck.

//	doIt
/**
	 * 	Create Check from line
	 *	@param line
	 *	@throws Exception for invalid bank accounts
	 */
private void createCheck(MPaySelectionLine line) throws Exception {
    //	Try to find one
    for (int i = 0; i < paySelectionChecks.size(); i++) {
        MPaySelectionCheck check = (MPaySelectionCheck) paySelectionChecks.get(i);
        //	Add to existing
        if (check.getC_BPartner_ID() == line.getInvoice().getC_BPartner_ID()) {
            check.addLine(line);
            if (!check.save())
                throw new IllegalStateException("Cannot save MPaySelectionCheck");
            line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
            line.setProcessed(true);
            if (!line.save())
                throw new IllegalStateException("Cannot save MPaySelectionLine");
            return;
        }
    }
    //	Create new
    String PaymentRule = line.getPaymentRule();
    if (p_PaymentRule != null) {
        if (!X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule))
            PaymentRule = p_PaymentRule;
    }
    MPaySelectionCheck check = new MPaySelectionCheck(line, PaymentRule);
    if (!check.isValid()) {
        int C_BPartner_ID = check.getC_BPartner_ID();
        MBPartner bp = MBPartner.get(getCtx(), C_BPartner_ID);
        String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.getName();
        throw new AdempiereUserError(msg);
    }
    if (!check.save())
        throw new IllegalStateException("Cannot save MPaySelectionCheck");
    line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
    line.setProcessed(true);
    if (!line.save())
        throw new IllegalStateException("Cannot save MPaySelectionLine");
    paySelectionChecks.add(check);
}
Also used : MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner)

Example 12 with AdempiereUserError

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

the class ProductUOMConvert method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    if (p_M_Product_ID == 0 || p_M_Product_To_ID == 0 || p_M_Locator_ID == 0 || p_Qty == null || Env.ZERO.compareTo(p_Qty) == 0)
        throw new AdempiereUserError("Invalid Parameter");
    //
    MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
    MProduct productTo = MProduct.get(getCtx(), p_M_Product_To_ID);
    log.info("Product=" + product + ", ProductTo=" + productTo + ", M_Locator_ID=" + p_M_Locator_ID + ", Qty=" + p_Qty);
    MUOMConversion[] conversions = MUOMConversion.getProductConversions(getCtx(), product.getM_Product_ID());
    MUOMConversion conversion = null;
    for (int i = 0; i < conversions.length; i++) {
        if (conversions[i].getC_UOM_To_ID() == productTo.getC_UOM_ID())
            conversion = conversions[i];
    }
    if (conversion == null)
        throw new AdempiereUserError("@NotFound@: @C_UOM_Conversion_ID@");
    MUOM uomTo = MUOM.get(getCtx(), productTo.getC_UOM_ID());
    BigDecimal qtyTo = p_Qty.divide(conversion.getDivideRate(), uomTo.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
    BigDecimal qtyTo6 = p_Qty.divide(conversion.getDivideRate(), 6, BigDecimal.ROUND_HALF_UP);
    if (qtyTo.compareTo(qtyTo6) != 0)
        throw new AdempiereUserError("@StdPrecision@: " + qtyTo + " <> " + qtyTo6 + " (" + p_Qty + "/" + conversion.getDivideRate() + ")");
    log.info(conversion + " -> " + qtyTo);
    //	Set to Beta
    return "Not completed yet";
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) AdempiereUserError(org.compiere.util.AdempiereUserError) BigDecimal(java.math.BigDecimal)

Example 13 with AdempiereUserError

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

the class OrderPOCreate method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message 
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("DateOrdered=" + p_DateOrdered_From + " - " + p_DateOrdered_To + " - C_BPartner_ID=" + p_C_BPartner_ID + " - Vendor_ID=" + p_Vendor_ID + " - IsDropShip=" + p_IsDropShip + " - C_Order_ID=" + p_C_Order_ID);
    if (p_C_Order_ID == 0 && p_DateOrdered_From == null && p_DateOrdered_To == null && p_C_BPartner_ID == 0 && p_Vendor_ID == 0)
        throw new AdempiereUserError("You need to restrict selection");
    //
    String sql = "SELECT * FROM C_Order o " + "WHERE o.IsSOTrx='Y'" + //	" AND o.Link_Order_ID IS NULL"
    " AND NOT EXISTS (SELECT * FROM C_OrderLine ol WHERE o.C_Order_ID=ol.C_Order_ID AND ol.Link_OrderLine_ID IS NOT NULL)";
    if (p_C_Order_ID != 0)
        sql += " AND o.C_Order_ID=?";
    else {
        if (p_C_BPartner_ID != 0)
            sql += " AND o.C_BPartner_ID=?";
        if (p_Vendor_ID != 0)
            sql += " AND EXISTS (SELECT * FROM C_OrderLine ol" + " INNER JOIN M_Product_PO po ON (ol.M_Product_ID=po.M_Product_ID) " + "WHERE o.C_Order_ID=ol.C_Order_ID AND po.C_BPartner_ID=?)";
        if (p_DateOrdered_From != null && p_DateOrdered_To != null)
            sql += "AND TRUNC(o.DateOrdered, 'DD') BETWEEN ? AND ?";
        else if (p_DateOrdered_From != null && p_DateOrdered_To == null)
            sql += "AND TRUNC(o.DateOrdered, 'DD') >= ?";
        else if (p_DateOrdered_From == null && p_DateOrdered_To != null)
            sql += "AND TRUNC(o.DateOrdered, 'DD') <= ?";
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int counter = 0;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        if (p_C_Order_ID != 0)
            pstmt.setInt(1, p_C_Order_ID);
        else {
            int index = 1;
            if (p_C_BPartner_ID != 0)
                pstmt.setInt(index++, p_C_BPartner_ID);
            if (p_Vendor_ID != 0)
                pstmt.setInt(index++, p_Vendor_ID);
            if (p_DateOrdered_From != null && p_DateOrdered_To != null) {
                pstmt.setTimestamp(index++, p_DateOrdered_From);
                pstmt.setTimestamp(index++, p_DateOrdered_To);
            } else if (p_DateOrdered_From != null && p_DateOrdered_To == null)
                pstmt.setTimestamp(index++, p_DateOrdered_From);
            else if (p_DateOrdered_From == null && p_DateOrdered_To != null)
                pstmt.setTimestamp(index++, p_DateOrdered_To);
        }
        rs = pstmt.executeQuery();
        while (rs.next()) {
            counter += createPOFromSO(new MOrder(getCtx(), rs, get_TrxName()));
        }
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (counter == 0)
        log.fine(sql);
    return "@Created@ " + counter;
}
Also used : MOrder(org.compiere.model.MOrder) AdempiereUserError(org.compiere.util.AdempiereUserError) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 14 with AdempiereUserError

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

the class ReplenishReport method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message 
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("M_Warehouse_ID=" + p_M_Warehouse_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + " - ReplenishmentCreate=" + p_ReplenishmentCreate + ", C_DocType_ID=" + p_C_DocType_ID);
    if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0)
        throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@");
    MWarehouse wh = MWarehouse.get(getCtx(), p_M_Warehouse_ID);
    if (wh.get_ID() == 0)
        throw new AdempiereSystemError("@FillMandatory@ @M_Warehouse_ID@");
    //
    prepareTable();
    fillTable(wh);
    //
    if (p_ReplenishmentCreate == null)
        return "OK";
    //
    MDocType dt = MDocType.get(getCtx(), p_C_DocType_ID);
    if (!dt.getDocBaseType().equals(p_ReplenishmentCreate))
        throw new AdempiereSystemError("@C_DocType_ID@=" + dt.getName() + " <> " + p_ReplenishmentCreate);
    //
    if (p_ReplenishmentCreate.equals("POO"))
        createPO();
    else if (p_ReplenishmentCreate.equals("POR"))
        createRequisition();
    else if (p_ReplenishmentCreate.equals("MMM"))
        createMovements();
    else if (p_ReplenishmentCreate.equals("DOO"))
        createDO();
    return m_info;
}
Also used : MDocType(org.compiere.model.MDocType) AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MWarehouse(org.compiere.model.MWarehouse)

Example 15 with AdempiereUserError

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

the class Doc method get.

//	get
/**
	 *  Create Posting document
	 *	@param ass accounting schema
	 *  @param AD_Table_ID Table ID of Documents
	 *  @param rs ResultSet
	 *  @param trxName transaction name
	 *  @return Document
	 * @throws AdempiereUserError 
	 */
public static Doc get(MAcctSchema[] ass, int AD_Table_ID, ResultSet rs, String trxName) throws AdempiereUserError {
    Doc doc = null;
    /* Classname of the Doc class follows this convention:
		 * if the prefix (letters before the first underscore _) is 1 character, then the class is Doc_TableWithoutPrefixWithoutUnderscores
		 * otherwise Doc_WholeTableWithoutUnderscores
		 * i.e. following this query
              SELECT t.ad_table_id, tablename, 
              	CASE 
              		WHEN instr(tablename, '_') = 2 
              		THEN 'Doc_' || substr(tablename, 3) 
              		WHEN instr(tablename, '_') > 2 
              		THEN 'Doc_' || 
              		ELSE '' 
              	REPLACE
              		(
              			tablename, '_', ''
              		)
              	END AS classname 
              FROM ad_table t, ad_column C 
              WHERE t.ad_table_id = C.ad_table_id AND
              	C.columnname = 'Posted' AND
              	isview = 'N' 
              ORDER BY 1
		 * This is:
		 * 224		GL_Journal			Doc_GLJournal
		 * 259		C_Order				Doc_Order
		 * 318		C_Invoice			Doc_Invoice
		 * 319		M_InOut				Doc_InOut
		 * 321		M_Inventory			Doc_Inventory
		 * 323		M_Movement			Doc_Movement
		 * 325		M_Production		Doc_Production
		 * 335		C_Payment			Doc_Payment
		 * 392		C_BankStatement		Doc_BankStatement
		 * 407		C_Cash				Doc_Cash
		 * 472		M_MatchInv			Doc_MatchInv
		 * 473		M_MatchPO			Doc_MatchPO
		 * 623		C_ProjectIssue		Doc_ProjectIssue
		 * 702		M_Requisition		Doc_Requisition
		 * 735		C_AllocationHdr		Doc_AllocationHdr
		 * 53027	PP_Order			Doc_PPOrder
		 * 53035	PP_Cost_Collector	Doc_PPCostCollector
		 * 53037	DD_Order			Doc_DDOrder
		 * 53092	HR_Process			Doc_HRProcess
		 */
    String tableName = MTable.getTableName(Env.getCtx(), AD_Table_ID);
    String packageName = "org.compiere.acct";
    String className = null;
    int firstUnderscore = tableName.indexOf("_");
    if (firstUnderscore == 1)
        className = packageName + ".Doc_" + tableName.substring(2).replaceAll("_", "");
    else
        className = packageName + ".Doc_" + tableName.replaceAll("_", "");
    try {
        Class<?> cClass = Class.forName(className);
        Constructor<?> cnstr = cClass.getConstructor(new Class[] { MAcctSchema[].class, ResultSet.class, String.class });
        doc = (Doc) cnstr.newInstance(ass, rs, trxName);
    } catch (Exception e) {
        s_log.log(Level.SEVERE, "Doc Class invalid: " + className + " (" + e.toString() + ")");
        throw new AdempiereUserError("Doc Class invalid: " + className + " (" + e.toString() + ")");
    }
    if (doc == null)
        s_log.log(Level.SEVERE, "Unknown AD_Table_ID=" + AD_Table_ID);
    return doc;
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) AdempiereUserError(org.compiere.util.AdempiereUserError) SQLException(java.sql.SQLException) DBException(org.adempiere.exceptions.DBException)

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