Search in sources :

Example 61 with PO

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());
    }
}
Also used : MTable(org.compiere.model.MTable) Point(java.awt.Point) PO(org.compiere.model.PO)

Example 62 with PO

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);
}
Also used : I_AD_WF_Node(org.compiere.model.I_AD_WF_Node) MWorkflow(org.compiere.wf.MWorkflow) MWFNode(org.compiere.wf.MWFNode) Properties(java.util.Properties) MResourceType(org.compiere.model.MResourceType) BigDecimal(java.math.BigDecimal) PO(org.compiere.model.PO)

Example 63 with PO

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);
    }
}
Also used : MResource(org.compiere.model.MResource) MUOM(org.compiere.model.MUOM) AdempiereException(org.adempiere.exceptions.AdempiereException) Properties(java.util.Properties) I_AD_Workflow(org.compiere.model.I_AD_Workflow) BigDecimal(java.math.BigDecimal) PO(org.compiere.model.PO)

Example 64 with PO

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;
}
Also used : PO(org.compiere.model.PO)

Example 65 with PO

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;
}
Also used : MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) PO(org.compiere.model.PO)

Aggregations

PO (org.compiere.model.PO)75 MTable (org.compiere.model.MTable)18 AdempiereException (org.adempiere.exceptions.AdempiereException)17 SQLException (java.sql.SQLException)16 Properties (java.util.Properties)13 BigDecimal (java.math.BigDecimal)11 Query (org.compiere.model.Query)8 Element (org.w3c.dom.Element)7 ArrayList (java.util.ArrayList)6 MEXPFormat (org.compiere.model.MEXPFormat)6 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)6 POInfo (org.compiere.model.POInfo)5 Trx (org.compiere.util.Trx)5 ModelCRUD (pl.x3E.adInterface.ModelCRUD)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 XFireFault (org.codehaus.xfire.fault.XFireFault)4 DataField (pl.x3E.adInterface.DataField)4 DataRow (pl.x3E.adInterface.DataRow)4 ParseException (java.text.ParseException)3