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;
}
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;
}
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();
}
Aggregations