Search in sources :

Example 76 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MRPUpdate method doIt.

//	prepare
/**
	 *  doIT - run process
	 */
protected String doIt() throws Exception {
    String result = null;
    ArrayList<Object> parameters = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType + "=? AND AD_Client_ID=?");
    parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant);
    parameters.add(m_AD_Client_ID);
    if (p_S_Resource_ID > 0) {
        whereClause.append(" AND S_Resource_ID=?");
        parameters.add(p_S_Resource_ID);
    }
    List<MResource> plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
    if (plants.size() == 0) {
        // TODO: translate
        throw new AdempiereException("No plants found");
    }
    for (MResource plant : plants) {
        log.info("Run MRP to Plant: " + plant.getName());
        parameters = new ArrayList<Object>();
        whereClause = new StringBuffer("AD_Client_ID=?");
        parameters.add(m_AD_Client_ID);
        if (p_AD_Org_ID > 0) {
            whereClause.append(" AND AD_Org_ID=?");
            parameters.add(p_AD_Org_ID);
        }
        List<MOrg> organizations = new Query(getCtx(), MOrg.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
        for (MOrg organization : organizations) {
            log.info("Run MRP to Organization: " + organization.getName());
            if (p_M_Warehouse_ID == 0) {
                MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), organization.getAD_Org_ID());
                for (MWarehouse w : ws) {
                    log.info("Run MRP to Wharehouse: " + w.getName());
                    deleteRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
                    createRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
                    result = result + "<br>finish MRP to Warehouse " + w.getName();
                }
            } else {
                log.info("Run MRP to Wharehouse: " + p_M_Warehouse_ID);
                deleteRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), p_M_Warehouse_ID);
                createRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), p_M_Warehouse_ID);
            }
            result = result + "<br>finish MRP to Organization " + organization.getName();
        }
        result = result + "<br>finish MRP to Plant " + plant.getName();
    }
    if (Util.isEmpty(result, true)) {
        // TODO: translate
        return "No records found";
    }
    return Msg.getMsg(getCtx(), "ProcessOK");
}
Also used : MResource(org.compiere.model.MResource) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) MWarehouse(org.compiere.model.MWarehouse) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 77 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class PrintPaperElementHandler method loadAttribute.

protected void loadAttribute(Attributes atts, String name, PO po) {
    final String strValueExact = atts.getValue(name);
    String strValue = strValueExact;
    if (Util.isEmpty(strValue, true)) {
        strValue = null;
    } else {
        strValue = strValue.trim();
    }
    final POInfo poInfo = POInfo.getPOInfo(po.getCtx(), getTable_ID());
    final Class<?> clazz = poInfo.getColumnClass(poInfo.getColumnIndex(name));
    if (strValue == null) {
        po.set_ValueOfColumn(name, null);
    } else if (clazz == BigDecimal.class) {
        po.set_ValueOfColumn(name, new BigDecimal(strValue));
    } else if (clazz == Integer.class) {
        po.set_ValueOfColumn(name, new BigDecimal(strValue).intValueExact());
    } else if (clazz == String.class) {
        po.set_ValueOfColumn(name, strValueExact);
    } else if (clazz == Boolean.class) {
        po.set_ValueOfColumn(name, Boolean.valueOf(strValue));
    } else if (clazz == Timestamp.class) {
        Timestamp ts = Timestamp.valueOf(strValue);
        po.set_ValueOfColumn(name, ts);
    } else {
        throw new AdempiereException("Class not supported - " + clazz);
    }
}
Also used : POInfo(org.compiere.model.POInfo) AdempiereException(org.adempiere.exceptions.AdempiereException) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 78 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MAllocationHdr method prepareIt.

//	invalidateIt
/**
	 *	Prepare Document
	 * 	@return new status (In Progress or Invalid) 
	 */
public String prepareIt() {
    log.info(toString());
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
    if (m_processMsg != null)
        return DocAction.STATUS_Invalid;
    //	Std Period open?
    MPeriod.testPeriodOpen(getCtx(), getDateAcct(), MDocType.DOCBASETYPE_PaymentAllocation, getAD_Org_ID());
    getLines(false);
    if (m_lines.length == 0) {
        m_processMsg = "@NoLines@";
        return DocAction.STATUS_Invalid;
    }
    // Stop the Document Workflow if invoice to allocate is as paid
    for (MAllocationLine line : m_lines) {
        if (line.getC_Invoice_ID() != 0) {
            final String whereClause = I_C_Invoice.COLUMNNAME_C_Invoice_ID + "=? AND " + I_C_Invoice.COLUMNNAME_IsPaid + "=? AND " + I_C_Invoice.COLUMNNAME_DocStatus + " NOT IN (?,?)";
            boolean InvoiceIsPaid = new Query(getCtx(), I_C_Invoice.Table_Name, whereClause, get_TrxName()).setClient_ID().setParameters(line.getC_Invoice_ID(), "Y", X_C_Invoice.DOCSTATUS_Voided, X_C_Invoice.DOCSTATUS_Reversed).match();
            if (InvoiceIsPaid)
                throw new AdempiereException("@ValidationError@ @C_Invoice_ID@ @IsPaid@");
        }
    }
    //	Add up Amounts & validate
    BigDecimal approval = Env.ZERO;
    for (int i = 0; i < m_lines.length; i++) {
        MAllocationLine line = m_lines[i];
        approval = approval.add(line.getWriteOffAmt()).add(line.getDiscountAmt());
        //	Make sure there is BP
        if (line.getC_BPartner_ID() == 0) {
            m_processMsg = "No Business Partner";
            return DocAction.STATUS_Invalid;
        }
    }
    setApprovalAmt(approval);
    //
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
    if (m_processMsg != null)
        return DocAction.STATUS_Invalid;
    m_justPrepared = true;
    if (!DOCACTION_Complete.equals(getDocAction()))
        setDocAction(DOCACTION_Complete);
    return DocAction.STATUS_InProgress;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) BigDecimal(java.math.BigDecimal)

Example 79 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MAlertRule method createReportFile.

//	getSql
/**
	 * Create Report File
	 * @param extension file extension
	 * @return newly created File
	 */
public File createReportFile(String extension) {
    if (Util.isEmpty(extension)) {
        throw new IllegalArgumentException("Parameter extension cannot be empty");
    }
    String name = new SimpleDateFormat("yyyyMMddhhmm").format(new Timestamp(System.currentTimeMillis())) + "_" + Util.stripDiacritics(getName().trim());
    File file = null;
    try {
        file = new File(System.getProperty("java.io.tmpdir"), name + "." + extension);
        file.createNewFile();
        return file;
    } catch (Exception e) {
        file = null;
    }
    // Fallback
    // TODO: add AD_AlertRule.FileName (maybe)
    String filePrefix = "Alert_";
    try {
        file = File.createTempFile(filePrefix, "." + extension);
    } catch (IOException e) {
        throw new AdempiereException(e);
    }
    return file;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) File(java.io.File) AdempiereException(org.adempiere.exceptions.AdempiereException) IOException(java.io.IOException)

Example 80 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class PO method deleteEx.

//	delete
/**
	 * Delete Current Record
	 * @param force delete also processed records
	 * @throws AdempiereException
	 * @see #delete(boolean)
	 */
public void deleteEx(boolean force) throws AdempiereException {
    if (!delete(force)) {
        String msg = null;
        ValueNamePair err = CLogger.retrieveError();
        if (err != null)
            msg = err.getName();
        if (msg == null || msg.length() == 0)
            msg = "DeleteError";
        throw new AdempiereException(msg);
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) ValueNamePair(org.compiere.util.ValueNamePair)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)326 BigDecimal (java.math.BigDecimal)79 SQLException (java.sql.SQLException)46 ArrayList (java.util.ArrayList)36 ResultSet (java.sql.ResultSet)33 PreparedStatement (java.sql.PreparedStatement)31 Timestamp (java.sql.Timestamp)31 MProduct (org.compiere.model.MProduct)28 List (java.util.List)25 Query (org.compiere.model.Query)20 File (java.io.File)17 Properties (java.util.Properties)16 PO (org.compiere.model.PO)16 Env (org.compiere.util.Env)15 MBPartner (org.compiere.model.MBPartner)14 ImmutableList (com.google.common.collect.ImmutableList)12 I_M_HU (de.metas.handlingunits.model.I_M_HU)12 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)12 ProcessInfo (org.compiere.process.ProcessInfo)12 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)11