Search in sources :

Example 56 with AdempiereUserError

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

the class InOutGenerate method doIt.

//	prepare
/**
	 * 	Generate Shipments
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("Selection=" + p_Selection + ", M_Warehouse_ID=" + p_M_Warehouse_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + ", Consolidate=" + p_ConsolidateDocument + ", IsUnconfirmed=" + p_IsUnconfirmedInOut + ", Movement=" + m_movementDate);
    if (p_M_Warehouse_ID == 0)
        throw new AdempiereUserError("@NotFound@ @M_Warehouse_ID@");
    if (//	VInOutGen
    p_Selection) {
        m_sql = "SELECT C_Order.* FROM C_Order, T_Selection " + "WHERE C_Order.DocStatus='CO' AND C_Order.IsSOTrx='Y' AND C_Order.AD_Client_ID=? " + "AND C_Order.C_Order_ID = T_Selection.T_Selection_ID " + "AND T_Selection.AD_PInstance_ID=? ";
    } else {
        m_sql = "SELECT * FROM C_Order o " + "WHERE DocStatus='CO' AND IsSOTrx='Y'" + //	No Offer,POS
        " AND o.C_DocType_ID IN (SELECT C_DocType_ID FROM C_DocType " + "WHERE DocBaseType='SOO' AND DocSubTypeSO NOT IN ('ON','OB','WR'))" + "	AND o.IsDropShip='N'" + //	No Manual
        " AND o.DeliveryRule<>'M'" + //	Open Order Lines with Warehouse
        " AND EXISTS (SELECT * FROM C_OrderLine ol " + //	#1
        "WHERE ol.M_Warehouse_ID=?";
        if (p_DatePromised != null)
            //	#2
            m_sql += " AND TRUNC(ol.DatePromised, 'DD')<=?";
        m_sql += " AND o.C_Order_ID=ol.C_Order_ID AND ol.QtyOrdered<>ol.QtyDelivered)";
        //
        if (p_C_BPartner_ID != 0)
            //	#3
            m_sql += " AND o.C_BPartner_ID=?";
    }
    m_sql += " ORDER BY M_Warehouse_ID, PriorityRule, M_Shipper_ID, C_BPartner_ID, C_BPartner_Location_ID, C_Order_ID";
    //	m_sql += " FOR UPDATE";
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(m_sql, get_TrxName());
        int index = 1;
        if (p_Selection) {
            pstmt.setInt(index++, Env.getAD_Client_ID(getCtx()));
            pstmt.setInt(index++, getAD_PInstance_ID());
        } else {
            pstmt.setInt(index++, p_M_Warehouse_ID);
            if (p_DatePromised != null)
                pstmt.setTimestamp(index++, p_DatePromised);
            if (p_C_BPartner_ID != 0)
                pstmt.setInt(index++, p_C_BPartner_ID);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, m_sql, e);
    }
    return generate(pstmt);
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) PreparedStatement(java.sql.PreparedStatement)

Example 57 with AdempiereUserError

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

the class OrderBatchProcess method doIt.

//	prepare
/**
	 * 	Process
	 *	@return msg
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_DocTypeTarget_ID=" + docTypeTargetId + ", DocStatus=" + docStatus + ", IsSelfService=" + isSelfService + ", C_BPartner_ID=" + partnerId + ", DateOrdered=" + dateOrderedFrom + "->" + dateOrderedTo + ", DocAction=" + docAction + ", IsDelivered=" + isDelivered + ", IsInvoiced=" + isInvoiced);
    if (docTypeTargetId == 0)
        throw new AdempiereUserError("@NotFound@: @C_DocTypeTarget_ID@");
    if (docStatus == null || docStatus.length() != 2)
        throw new AdempiereUserError("@NotFound@: @DocStatus@");
    if (docAction == null || docAction.length() != 2)
        throw new AdempiereUserError("@NotFound@: @DocAction@");
    //
    StringBuffer sql = new StringBuffer("SELECT * FROM C_Order o " + " WHERE o.C_DocTypeTarget_ID=? AND o.DocStatus=? ");
    if (isSelfService != null && isSelfService.length() == 1)
        sql.append(" AND o.IsSelfService='").append(isSelfService).append("'");
    if (partnerId != 0)
        sql.append(" AND o.C_BPartner_ID=").append(partnerId);
    if (dateOrderedFrom != null)
        sql.append(" AND TRUNC(o.DateOrdered, 'DD') >= ").append(DB.TO_DATE(dateOrderedFrom, true));
    if (dateOrderedTo != null)
        sql.append(" AND TRUNC(o.DateOrdered, 'DD') <= ").append(DB.TO_DATE(dateOrderedTo, true));
    if ("Y".equals(isDelivered))
        sql.append(" AND NOT EXISTS (SELECT l.C_OrderLine_ID FROM C_OrderLine l ").append(" WHERE l.C_Order_ID=o.C_Order_ID AND l.QtyOrdered>l.QtyDelivered) ");
    else if ("N".equals(isDelivered))
        sql.append(" AND EXISTS (SELECT l.C_OrderLine_ID FROM C_OrderLine l ").append(" WHERE l.C_Order_ID=o.C_Order_ID AND l.QtyOrdered>l.QtyDelivered) ");
    if ("Y".equals(isInvoiced))
        sql.append(" AND NOT EXISTS (SELECT l.C_OrderLine_ID FROM C_OrderLine l ").append(" WHERE l.C_Order_ID=o.C_Order_ID AND l.QtyOrdered>l.QtyInvoiced) ");
    else if ("N".equals(isInvoiced))
        sql.append(" AND EXISTS (SELECT l.C_OrderLine_ID FROM C_OrderLine l ").append(" WHERE l.C_Order_ID=o.C_Order_ID AND l.QtyOrdered>l.QtyInvoiced) ");
    int counter = 0;
    int errCounter = 0;
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
        pstmt.setInt(1, docTypeTargetId);
        pstmt.setString(2, docStatus);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            if (process(rs.getInt(I_C_Order.COLUMNNAME_C_Order_ID)))
                counter++;
            else
                errCounter++;
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql.toString(), e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    return "@Updated@=" + counter + ", @Errors@=" + errCounter;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 58 with AdempiereUserError

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

the class MatchPODelete method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("M_MatchPO_ID=" + p_M_MatchPO_ID);
    MMatchPO po = new MMatchPO(getCtx(), p_M_MatchPO_ID, get_TrxName());
    if (po.get_ID() == 0)
        throw new AdempiereUserError("@NotFound@ @M_MatchPO_ID@ " + p_M_MatchPO_ID);
    //
    MOrderLine orderLine = null;
    boolean isMatchReceipt = (po.getM_InOutLine_ID() != 0);
    if (isMatchReceipt) {
        orderLine = new MOrderLine(getCtx(), po.getC_OrderLine_ID(), get_TrxName());
        orderLine.setQtyReserved(orderLine.getQtyReserved().add(po.getQty()));
    }
    //
    if (po.delete(true)) {
        if (isMatchReceipt) {
            if (!orderLine.save(get_TrxName()))
                throw new AdempiereUserError("Delete MatchPO failed to restore PO's On Ordered Qty");
        }
        return "@OK@";
    }
    po.saveEx();
    return "@Error@";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MMatchPO(org.compiere.model.MMatchPO) MOrderLine(org.compiere.model.MOrderLine)

Example 59 with AdempiereUserError

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

the class SLAMeasureProcess method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("PA_SLA_Measure_ID=" + p_PA_SLA_Measure_ID);
    MSLAMeasure measure = new MSLAMeasure(getCtx(), p_PA_SLA_Measure_ID, get_TrxName());
    if (measure.get_ID() == 0)
        throw new AdempiereUserError("@PA_SLA_Measure_ID@ " + p_PA_SLA_Measure_ID);
    MSLAGoal goal = new MSLAGoal(getCtx(), measure.getPA_SLA_Goal_ID(), get_TrxName());
    if (goal.get_ID() == 0)
        throw new AdempiereUserError("@PA_SLA_Goal_ID@ " + measure.getPA_SLA_Goal_ID());
    MSLACriteria criteria = MSLACriteria.get(getCtx(), goal.getPA_SLA_Criteria_ID(), get_TrxName());
    if (criteria.get_ID() == 0)
        throw new AdempiereUserError("@PA_SLA_Criteria_ID@ " + goal.getPA_SLA_Criteria_ID());
    SLACriteria pgm = criteria.newInstance();
    //
    goal.setMeasureActual(pgm.calculateMeasure(goal));
    goal.setDateLastRun(new Timestamp(System.currentTimeMillis()));
    goal.saveEx();
    //
    return "@MeasureActual@=" + goal.getMeasureActual();
}
Also used : MSLACriteria(org.compiere.model.MSLACriteria) AdempiereUserError(org.compiere.util.AdempiereUserError) MSLAGoal(org.compiere.model.MSLAGoal) MSLACriteria(org.compiere.model.MSLACriteria) Timestamp(java.sql.Timestamp) MSLAMeasure(org.compiere.model.MSLAMeasure)

Example 60 with AdempiereUserError

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

the class YearCreatePeriods method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    MYear year = new MYear(getCtx(), yearId, get_TrxName());
    if (yearId == 0 || year.get_ID() != yearId)
        throw new AdempiereUserError("@NotFound@: @C_Year_ID@ - " + yearId);
    log.info(year.toString());
    //
    if (year.createStdPeriods(null, getStartDate(), getDateFormat()))
        return "@OK@";
    return "@Error@";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MYear(org.compiere.model.MYear)

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