use of org.compiere.model.MUOM in project adempiere by adempiere.
the class myJTree method action_loadBOM.
// actionPerformed
/**
* Action: Fill Tree with all nodes
*/
private void action_loadBOM() {
//m_frame.setBusy(true);
m_frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
reload = false;
int M_Product_ID = getM_Product_ID();
if (M_Product_ID == 0)
return;
MProduct M_Product = MProduct.get(getCtx(), M_Product_ID);
treeInfo.setText(" Current Selection: " + M_Product.getValue());
Vector<Object> line = new Vector<Object>(17);
// 0 Select
line.add(new Boolean(false));
// 1 IsActive
line.add(new Boolean(M_Product.isActive()));
// 2 Line
line.add(new Integer(0));
KeyNamePair pp = new KeyNamePair(M_Product.getM_Product_ID(), M_Product.getValue().concat("_").concat(M_Product.getName()));
// 3 M_Product_ID
line.add(pp);
MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
KeyNamePair uom = new KeyNamePair(M_Product.getC_UOM_ID(), u.getUOMSymbol());
// 4 C_UOM_ID
line.add(uom);
// 5 QtyBOM
line.add(Env.ONE);
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(line);
m_root = (DefaultMutableTreeNode) parent.getRoot();
dataBOM.clear();
if (isImplosion()) {
for (MProductBOM bomline : getParentBOMs(M_Product_ID)) {
addParent(bomline, parent);
}
m_tree = new myJTree(parent);
m_tree.addMouseListener(mouseListener);
} else {
for (MProductBOM bom : getChildBOMs(M_Product_ID, true)) {
addChild(bom, parent);
}
m_tree = new myJTree(parent);
m_tree.addMouseListener(mouseListener);
}
/* MouseListener ml = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int selRow = m_tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = m_tree.getPathForLocation(e.getX(), e.getY());
if(selRow != -1) {
if(e.getClickCount() == 1) {
mySingleClick(selRow, selPath);
}
// else if(e.getClickCount() == 2) {
// myDoubleClick(selRow, selPath);
// }
}
}
private void mySingleClick(int selRow, TreePath selPath) {
// TODO Auto-generated method stub
}
};
m_tree.addMouseListener(ml);
*/
m_tree.addTreeSelectionListener(this);
treePane.getViewport().add(m_tree, null);
loadTableBOM();
dataPane.getViewport().add(tableBOM, null);
// 4Layers - Set divider location
splitPane.setDividerLocation(DIVIDER_LOCATION);
// 4Layers - end
// Popup
// if (m_selected_id != 0)
// {
// }
//m_frame.setBusy(false);
m_frame.setCursor(Cursor.getDefaultCursor());
}
use of org.compiere.model.MUOM in project adempiere by adempiere.
the class CRPSummary method Summary.
public void Summary(Timestamp start, Timestamp finish, MResource r) {
GregorianCalendar gc1 = new GregorianCalendar();
gc1.setTimeInMillis(start.getTime());
gc1.clear(Calendar.MILLISECOND);
gc1.clear(Calendar.SECOND);
gc1.clear(Calendar.MINUTE);
gc1.clear(Calendar.HOUR_OF_DAY);
GregorianCalendar gc2 = new GregorianCalendar();
gc2.setTimeInMillis(finish.getTime());
gc2.clear(Calendar.MILLISECOND);
gc2.clear(Calendar.SECOND);
gc2.clear(Calendar.MINUTE);
gc2.clear(Calendar.HOUR_OF_DAY);
MResourceType t = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
long hours = 0;
if (t.isTimeSlot())
hours = getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotStart());
else
hours = 24;
boolean available = false;
ArrayList<Col> list = new ArrayList<Col>();
int col = 0;
int row = 1;
int summary = 0;
Col cols = new Col();
cols.setFrom("Past Due");
cols.setTo(start.toString());
cols.setDays(0);
cols.setCapacity(0);
cols.setLoad(0);
cols.setSummary(0);
list.add(0, cols);
col++;
while (gc1.before(gc2)) {
gc1.add(Calendar.DATE, 1);
switch(gc1.get(Calendar.DAY_OF_WEEK)) {
case Calendar.SUNDAY:
if (t.isOnSunday())
available = true;
break;
case Calendar.MONDAY:
if (t.isOnMonday())
available = true;
break;
case Calendar.TUESDAY:
if (t.isOnTuesday())
available = true;
break;
case Calendar.WEDNESDAY:
if (t.isOnWednesday())
available = true;
break;
case Calendar.THURSDAY:
if (t.isOnThursday())
available = true;
break;
case Calendar.FRIDAY:
if (t.isOnFriday())
available = true;
break;
case Calendar.SATURDAY:
if (t.isOnSaturday())
available = true;
break;
}
if (available) {
cols = new Col();
cols.setFrom(gc1.getTime().toString());
cols.setTo(gc1.getTime().toString());
cols.setDays(1);
Long Hours = new Long(hours);
cols.setCapacity(Hours.intValue());
int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", r.getS_Resource_ID());
MUOM oum = MUOM.get(getCtx(), C_UOM_ID);
if (oum.isHour()) {
Timestamp date = new Timestamp(gc1.getTimeInMillis());
int seconds = getLoad(r.getS_Resource_ID(), date, date);
cols.setLoad(seconds / 3600);
}
cols.setSummary(summary + cols.getDifference());
summary = cols.getSummary();
list.add(col, cols);
}
}
col = 0;
boolean newrow = true;
Col[] lines = new Col[list.size()];
//set Title
for (int z = 0; z <= lines.length; z++) {
}
for (int i = 0; i <= lines.length; i++) {
if (newrow) {
X_T_MRP_CRP crp = new X_T_MRP_CRP(getCtx(), 0, null);
crp.setDescription("CRP Resource" + r.getName());
//crp.setRange00(lines[i].getFrom() + "/" + lines[i].getTo());
}
switch(col) {
case 0:
col++;
case 1:
col++;
case 2:
col++;
case 3:
col++;
case 4:
col++;
case 5:
col++;
case 6:
col++;
case 7:
col++;
case 8:
col++;
case 9:
col++;
case 10:
col++;
case 11:
col++;
case 12:
col = 0;
newrow = true;
}
col++;
}
}
use of org.compiere.model.MUOM in project adempiere by adempiere.
the class NoUOMConversionException method buildMessage.
private static String buildMessage(int M_Product_ID, int C_UOM_ID, int C_UOM_To_ID) {
StringBuffer sb = new StringBuffer("@" + AD_Message + "@ - ");
//
sb.append("@M_Product_ID@:");
MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
if (product != null) {
sb.append(product.getValue()).append("_").append(product.getName());
}
//
if (C_UOM_ID > 0 || product == null) {
sb.append(" @C_UOM_ID@:");
MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID);
if (uom != null) {
sb.append(uom.getUOMSymbol());
}
}
//
sb.append(" @C_UOM_To_ID@:");
MUOM uomTo = MUOM.get(Env.getCtx(), C_UOM_To_ID);
if (uomTo != null) {
sb.append(uomTo.getUOMSymbol());
}
//
return sb.toString();
}
use of org.compiere.model.MUOM in project adempiere by adempiere.
the class ForecastRunCreate method createForecastRunResult.
/**
* Create the Forecast Result
*
* @param M_Warehouse_ID
* @return no records processed
*/
private int createForecastRunResult(int M_Warehouse_ID) {
// total record processed
int records = 0;
ForecastEngine engine = ForecastFactory.getForecastEngine(getAD_Client_ID());
// Generate ForecastEntry based on forecast rule
for (MPPForecastRunMaster master : MPPForecastRunMaster.getLines(getCtx(), p_PP_ForecastRun_ID, get_TrxName())) {
DataSet series = new DataSet();
series.setPeriods(m_run.getPeriodHistory());
MProduct product = MProduct.get(getCtx(), master.getM_Product_ID());
List<MPPForecastRunDetail> details = MPPForecastRunMaster.getDetails(getCtx(), master.get_ID(), get_TrxName());
for (MPPForecastRunDetail detail : details) {
MPPPeriod period = (MPPPeriod) detail.getPP_Period();
DataElement data = new DataElement(master.get_ID(), period.getPeriodNo(), detail.getQtyCalculated(), null);
series.addDataElement(data);
}
DataSet results = engine.getForecast(m_forecast_rule.getCalculationClass(), master.get_ID(), series, master.getFactorAlpha().doubleValue(), master.getFactorGamma().doubleValue(), master.getFactorBeta().doubleValue(), master.getFactorMultiplier().doubleValue(), master.getFactorScale().doubleValue(), master.getFactorUser().doubleValue());
Enumeration<DataElement> elements = results.getDataElements();
while (elements.hasMoreElements()) {
DataElement element = elements.nextElement();
MUOM uom = (MUOM) product.getC_UOM();
MPPForecastRunResult result = new MPPForecastRunResult(getCtx(), 0, get_TrxName());
result.setPP_ForecastRun_ID(m_run.get_ID());
result.setPP_ForecastRunMaster_ID(element.getKey());
result.setDescription(element.getDescription());
BigDecimal qty = (BigDecimal) element.getValue();
result.setQtyCalculated(qty);
result.setQtyPlan(uom.round(qty, true));
result.setIsActive(true);
result.setPP_Period_ID(MPPPeriod.getIDByPeriodNo(m_period_definition_target, element.getPeriodNo()));
result.setPeriodNo(element.getPeriodNo());
result.saveEx();
records++;
}
}
// m_run.saveEx();
return records;
}
use of org.compiere.model.MUOM 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);
}
}
Aggregations