use of org.compiere.model.PO in project adempiere by adempiere.
the class VSortTab method saveData.
// registerAPanel
/** (non-Javadoc)
* @see org.compiere.grid.APanelTab#saveData()
*/
public void saveData() {
if (!m_aPanel.aSave.isEnabled())
return;
log.fine("");
boolean ok = true;
StringBuffer info = new StringBuffer();
MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
// noList - Set SortColumn to null and optional YesNo Column to 'N'
for (int i = 0; i < noModel.getSize(); i++) {
ListItem pp = (ListItem) noModel.getElementAt(i);
if (!pp.isUpdateable())
continue;
if (pp.getSortNo() == 0 && (m_ColumnYesNoName == null || !pp.isYes()))
// no changes
continue;
//
PO po = table.getPO(pp.getKey(), null);
po.set_ValueOfColumn(m_ColumnSortName, 0);
po.set_ValueOfColumn(m_ColumnYesNoName, false);
if (po.save()) {
pp.setSortNo(0);
pp.setIsYes(false);
} else {
ok = false;
if (info.length() > 0)
info.append(", ");
info.append(pp.getName());
log.log(Level.SEVERE, "NoModel - Not updated: " + m_KeyColumnName + "=" + pp.getKey());
}
}
// yesList - Set SortColumn to value and optional YesNo Column to 'Y'
int index = 0;
for (int i = 0; i < yesModel.getSize(); i++) {
ListItem pp = (ListItem) yesModel.getElementAt(i);
if (!pp.isUpdateable())
continue;
index += 10;
if (pp.getSortNo() == index && (m_ColumnYesNoName == null || pp.isYes()))
// no changes
continue;
//
PO po = table.getPO(pp.getKey(), null);
po.set_ValueOfColumn(m_ColumnSortName, index);
po.set_ValueOfColumn(m_ColumnYesNoName, true);
if (po.save()) {
pp.setSortNo(index);
pp.setIsYes(true);
} else {
ok = false;
if (info.length() > 0)
info.append(", ");
info.append(pp.getName());
log.log(Level.SEVERE, "YesModel - Not updated: " + m_KeyColumnName + "=" + pp.getKey());
}
}
//
if (ok) {
setIsChanged(false);
} else {
ADialog.error(m_WindowNo, null, "SaveError", info.toString());
}
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method calculateDuration.
public BigDecimal calculateDuration(I_AD_Workflow wf, I_S_Resource plant, BigDecimal qty) {
if (plant == null)
return Env.ZERO;
final Properties ctx = ((PO) wf).getCtx();
final MResourceType S_ResourceType = MResourceType.get(ctx, plant.getS_ResourceType_ID());
BigDecimal AvailableDayTime = new BigDecimal(S_ResourceType.getTimeSlotHours());
int AvailableDays = S_ResourceType.getAvailableDaysWeek();
double durationBaseSec = getDurationBaseSec(wf.getDurationUnit());
double durationTotal = 0.0;
MWFNode[] nodes = ((MWorkflow) wf).getNodes(false, Env.getAD_Client_ID(ctx));
for (I_AD_WF_Node node : nodes) {
// Qty independent times:
durationTotal += node.getQueuingTime();
durationTotal += node.getSetupTime();
durationTotal += node.getWaitingTime();
durationTotal += node.getMovingTime();
// Get OverlapUnits - number of units that must be completed before they are moved the next activity
double overlapUnits = qty.doubleValue();
if (node.getOverlapUnits() > 0 && node.getOverlapUnits() < overlapUnits) {
overlapUnits = node.getOverlapUnits();
}
double durationBeforeOverlap = node.getDuration() * overlapUnits;
durationTotal += durationBeforeOverlap;
}
BigDecimal requiredTime = BigDecimal.valueOf(durationTotal * durationBaseSec / 60 / 60);
// TODO: implement here, Victor's suggestion - https://sourceforge.net/forum/message.php?msg_id=5179460
// Weekly Factor
BigDecimal WeeklyFactor = new BigDecimal(7).divide(new BigDecimal(AvailableDays), 8, RoundingMode.UP);
return (requiredTime.multiply(WeeklyFactor)).divide(AvailableDayTime, 0, RoundingMode.UP);
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method getResourceBaseValue.
protected BigDecimal getResourceBaseValue(int S_Resource_ID, I_AD_WF_Node node, I_PP_Cost_Collector cc) {
if (node == null)
node = cc.getPP_Order_Node().getAD_WF_Node();
final Properties ctx = (node instanceof PO ? ((PO) node).getCtx() : Env.getCtx());
final MResource resource = MResource.get(ctx, S_Resource_ID);
final MUOM resourceUOM = MUOM.get(ctx, resource.getC_UOM_ID());
//
if (isTime(resourceUOM)) {
BigDecimal duration = calculateDuration(node, cc);
I_AD_Workflow wf = MWorkflow.get(ctx, node.getAD_Workflow_ID());
BigDecimal convertedDuration = convertDuration(duration, wf.getDurationUnit(), resourceUOM);
return convertedDuration;
} else {
throw new AdempiereException("@NotSupported@ @C_UOM_ID@ - " + resourceUOM);
}
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class POWrapper method isNull.
/**
* Check if given columnName's value is null
*
* @param model
* @param columnName
* @return true if columnName's value is null
*/
public static boolean isNull(Object model, String columnName) {
final PO po = getPO(model, false);
if (po == null) {
return true;
}
final Object value = po.get_Value(columnName);
return value == null;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class MRelationType method whereClauseMatches.
static boolean whereClauseMatches(PO po, String where) {
if (Util.isEmpty(where, true)) {
logger.fine("whereClause is empty. Returning true");
return true;
}
final String parsedWhere = parseWhereClause(po, where);
if (Util.isEmpty(parsedWhere)) {
return false;
}
final PO result = new Query(po.getCtx(), po.get_TableName(), parsedWhere, po.get_TrxName()).first();
final boolean match = result != null;
logger.fine("whereClause='" + parsedWhere + "' matches po='" + po + "':" + match);
return match;
}
Aggregations