Search in sources :

Example 1 with MSLAMeasure

use of org.compiere.model.MSLAMeasure in project adempiere by adempiere.

the class DeliveryAccuracy method createMeasures.

/**
	 * 	Create new Measures for the Goal
	 * 	@param goal the goal
	 * 	@return number created
	 */
public int createMeasures(MSLAGoal goal) {
    String sql = //	1..2
    "SELECT M_InOut_ID, io.MovementDate-o.DatePromised," + " io.MovementDate, o.DatePromised, o.DocumentNo " + "FROM M_InOut io" + " INNER JOIN C_Order o ON (io.C_Order_ID=o.C_Order_ID) " + "WHERE io.C_BPartner_ID=?" + " AND NOT EXISTS " + "(SELECT * FROM PA_SLA_Measure m " + "WHERE m.PA_SLA_Goal_ID=?" + " AND m.AD_Table_ID=" + MInOut.Table_ID + " AND m.Record_ID=io.M_InOut_ID)";
    int counter = 0;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, goal.getC_BPartner_ID());
        pstmt.setInt(2, goal.getPA_SLA_Goal_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int M_InOut_ID = rs.getInt(1);
            BigDecimal MeasureActual = rs.getBigDecimal(2);
            Timestamp MovementDate = rs.getTimestamp(3);
            String Description = rs.getString(5) + ": " + rs.getTimestamp(4);
            if (goal.isDateValid(MovementDate)) {
                MSLAMeasure measure = new MSLAMeasure(goal, MovementDate, MeasureActual, Description);
                measure.setLink(MInOut.Table_ID, M_InOut_ID);
                if (measure.save())
                    counter++;
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "createMeasures", e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return counter;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MSLAMeasure(org.compiere.model.MSLAMeasure)

Example 2 with MSLAMeasure

use of org.compiere.model.MSLAMeasure in project adempiere by adempiere.

the class DeliveryAccuracy method calculateMeasure.

//	createMeasures
/**************************************************************************
	 * 	Calculate Goal Actual from unprocessed Measures
	 *	@return goal actual measure
	 */
public BigDecimal calculateMeasure(MSLAGoal goal) {
    //	Average
    BigDecimal retValue = Env.ZERO;
    BigDecimal total = Env.ZERO;
    int count = 0;
    //
    MSLAMeasure[] measures = goal.getAllMeasures();
    for (int i = 0; i < measures.length; i++) {
        MSLAMeasure measure = measures[i];
        if (!measure.isActive() || (goal.getValidFrom() != null && measure.getDateTrx().before(goal.getValidFrom())) || (goal.getValidTo() != null && measure.getDateTrx().after(goal.getValidTo())))
            continue;
        //
        total = total.add(measure.getMeasureActual());
        count++;
        //
        if (!measure.isProcessed()) {
            measure.setProcessed(true);
            measure.saveEx();
        }
    }
    //	Goal Expired
    if (goal.getValidTo() != null && goal.getValidTo().after(new Timestamp(System.currentTimeMillis())))
        goal.setProcessed(true);
    //	Calculate with 2 digits precision
    if (count != 0)
        retValue = total.divide(new BigDecimal(count), 2, BigDecimal.ROUND_HALF_UP);
    return retValue;
}
Also used : Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MSLAMeasure(org.compiere.model.MSLAMeasure)

Example 3 with MSLAMeasure

use of org.compiere.model.MSLAMeasure 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)

Aggregations

Timestamp (java.sql.Timestamp)3 MSLAMeasure (org.compiere.model.MSLAMeasure)3 BigDecimal (java.math.BigDecimal)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 MSLACriteria (org.compiere.model.MSLACriteria)1 MSLAGoal (org.compiere.model.MSLAGoal)1 AdempiereUserError (org.compiere.util.AdempiereUserError)1