Search in sources :

Example 36 with PO

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

the class MRP method calculatePlan.

/**************************************************************************
	 * 	Calculate Plan this product
	 *	@param PP_MRP_ID MRP ID
	 *  @param M_Warehouse_ID Warehoue ID
	 *  @param product Product
	 *  @param DemandDateStartSchedule Demand Date Start Schedule
	 * @throws SQLException 
	 */
private void calculatePlan(int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID, int PP_MRP_ID, MProduct product, Timestamp DemandDateStartSchedule, String trxName) throws SQLException {
    //Set Yield o QtyGrossReqs
    // Note : the variables  DemandDateStartSchedule , DemandDateFinishSchedule are same DatePromised to Demands Sales Order Type
    log.info("Create Plan ...");
    // Check Internal Error: product from data planning should be the same with the product given as argument 
    if (m_product_planning.getM_Product_ID() != product.get_ID()) {
        throw new IllegalStateException("MRP Internal Error:" + " DataPlanningProduct(" + m_product_planning.getM_Product_ID() + ")" + " <> Product(" + product + ")");
    }
    final BigDecimal yield = BigDecimal.valueOf(m_product_planning.getYield());
    if (yield.signum() != 0) {
        QtyGrossReqs = QtyGrossReqs.multiply(Env.ONEHUNDRED).divide(yield, 4, RoundingMode.HALF_UP);
    }
    BigDecimal QtyNetReqs = getNetRequirements(AD_Client_ID, AD_Org_ID, M_Warehouse_ID, product, DemandDateStartSchedule, trxName);
    BigDecimal QtyPlanned = Env.ZERO;
    ((PO) m_product_planning).dump();
    log.info("                    Product:" + product);
    log.info(" Demand Date Start Schedule:" + DemandDateStartSchedule);
    log.info("           DatePromisedFrom:" + DatePromisedFrom + " DatePromisedTo:" + DatePromisedTo);
    log.info("                Qty Planned:" + QtyPlanned);
    log.info("     Qty Scheduled Receipts:" + QtyScheduledReceipts);
    log.info("           QtyProjectOnHand:" + QtyProjectOnHand);
    log.info("               QtyGrossReqs:" + QtyGrossReqs);
    log.info("                     Supply:" + (QtyScheduledReceipts).add(QtyProjectOnHand));
    log.info("                 QtyNetReqs:" + QtyNetReqs);
    if (QtyNetReqs.signum() > 0) {
        // entire qty is available or scheduled to receipt
        QtyProjectOnHand = QtyNetReqs;
        QtyNetReqs = Env.ZERO;
        QtyScheduledReceipts = Env.ZERO;
        QtyPlanned = Env.ZERO;
        QtyGrossReqs = Env.ZERO;
        return;
    } else {
        QtyPlanned = QtyNetReqs.negate();
        QtyGrossReqs = Env.ZERO;
        QtyScheduledReceipts = Env.ZERO;
    }
    // Check Order Min 
    if (QtyPlanned.signum() > 0 && m_product_planning.getOrder_Min().signum() > 0) {
        if (m_product_planning.getOrder_Min().compareTo(QtyPlanned) > 0) {
            String comment = Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_Order_Min) + " : " + m_product_planning.getOrder_Min();
            createMRPNote("MRP-080", AD_Org_ID, PP_MRP_ID, product, null, QtyPlanned, comment, trxName);
        }
        QtyPlanned = QtyPlanned.max(m_product_planning.getOrder_Min());
    }
    // Check Order Pack
    if (m_product_planning.getOrder_Pack().signum() > 0 && QtyPlanned.signum() > 0) {
        QtyPlanned = m_product_planning.getOrder_Pack().multiply(QtyPlanned.divide(m_product_planning.getOrder_Pack(), 0, BigDecimal.ROUND_UP));
    }
    // Check Order Max                                                
    if (QtyPlanned.compareTo(m_product_planning.getOrder_Max()) > 0 && m_product_planning.getOrder_Max().signum() > 0) {
        String comment = Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_Order_Max) + " : " + m_product_planning.getOrder_Max();
        createMRPNote("MRP-090", AD_Org_ID, PP_MRP_ID, product, null, QtyPlanned, comment, trxName);
    }
    QtyProjectOnHand = QtyPlanned.add(QtyNetReqs);
    log.info("QtyNetReqs:" + QtyNetReqs);
    log.info("QtyPlanned:" + QtyPlanned);
    log.info("QtyProjectOnHand:" + QtyProjectOnHand);
    // of the requirement that created the demand.
    if (TimeFence != null && DemandDateStartSchedule.compareTo(TimeFence) < 0) {
        String comment = Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_TimeFence) + " : " + m_product_planning.getTimeFence() + "-" + Msg.getMsg(getCtx(), "Date") + " : " + TimeFence + " " + Msg.translate(getCtx(), MPPOrder.COLUMNNAME_DatePromised) + " : " + DemandDateStartSchedule;
        createMRPNote("MRP-100", AD_Org_ID, PP_MRP_ID, product, null, QtyPlanned, comment, trxName);
    }
    // This message is created if the flag 'Create Plan' is No.
    if (m_product_planning.isCreatePlan() == false && QtyPlanned.signum() > 0) {
        createMRPNote("MRP-020", AD_Org_ID, PP_MRP_ID, product, null, QtyPlanned, null, trxName);
        return;
    }
    if (QtyPlanned.signum() > 0) {
        int loops = 1;
        if (m_product_planning.getOrder_Policy().equals(X_PP_Product_Planning.ORDER_POLICY_FixedOrderQuantity)) {
            if (m_product_planning.getOrder_Qty().signum() != 0)
                loops = (QtyPlanned.divide(m_product_planning.getOrder_Qty(), 0, BigDecimal.ROUND_UP)).intValueExact();
            QtyPlanned = m_product_planning.getOrder_Qty();
        }
        for (int ofq = 1; ofq <= loops; ofq++) {
            log.info("Is Purchased: " + product.isPurchased() + " Is BOM: " + product.isBOM());
            try {
                createSupply(AD_Org_ID, PP_MRP_ID, product, QtyPlanned, DemandDateStartSchedule, trxName);
            } catch (Exception e) {
                // on - Cannot Create Document
                // Indicates that there was an error during document creation
                createMRPNote("MRP-160", AD_Org_ID, PP_MRP_ID, product, QtyPlanned, DemandDateStartSchedule, e, trxName);
            }
        }
    // end for oqf
    } else {
        log.info("No Create Plan");
    }
}
Also used : BigDecimal(java.math.BigDecimal) DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) MProductPO(org.compiere.model.MProductPO) PO(org.compiere.model.PO)

Example 37 with PO

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

the class AdempiereTreeModel method saveChangedNodes.

public void saveChangedNodes(MTreeNode from, MTreeNode to) {
    int AD_Tree_ID = m_MTree.getAD_Tree_ID();
    Trx trx = Trx.get(Trx.createTrxName("AdempiereTreeModel"), true);
    try {
        for (int i = 0; i < from.getChildCount(); i++) {
            MTreeNode nd = (MTreeNode) from.getChildAt(i);
            String whereClause = "AD_Tree_ID=" + AD_Tree_ID + " AND Node_ID=" + nd.getNode_ID();
            PO tree = MTable.get(Env.getCtx(), m_MTree.getNodeTableName()).getPO(whereClause, trx.getTrxName());
            if (tree.get_ValueAsInt("Parent_ID") != from.getNode_ID() || tree.get_ValueAsInt("SeqNo") != i) {
                tree.set_CustomColumn("Parent_ID", from.getNode_ID());
                tree.set_CustomColumn("SeqNo", i);
                tree.saveEx();
            }
        }
        if (from != to) {
            // Renumber and set parent ID for the children of the 'to' node.
            int nextSeqNo = 0;
            for (int i = 0; i < to.getChildCount(); i++) {
                // Skip the entry of the 'from' node to avoid duplication
                if (i == Integer.parseInt(from.getSeqNo()))
                    continue;
                MTreeNode nd = (MTreeNode) to.getChildAt(i);
                String whereClause = "AD_Tree_ID=" + AD_Tree_ID + " AND Node_ID=" + nd.getNode_ID();
                PO tree = MTable.get(Env.getCtx(), m_MTree.getNodeTableName()).getPO(whereClause, trx.getTrxName());
                if (tree.get_ValueAsInt("Parent_ID") != to.getNode_ID() || tree.get_ValueAsInt("SeqNo") < nextSeqNo) {
                    tree.set_CustomColumn("Parent_ID", to.getNode_ID());
                    tree.set_CustomColumn("SeqNo", nextSeqNo++);
                    tree.saveEx();
                } else {
                    nextSeqNo = tree.get_ValueAsInt("SeqNo") + 1;
                }
            }
        }
        trx.commit(true);
    } catch (Exception e) {
        trx.rollback();
        log.log(Level.SEVERE, "move", e);
    }
    trx.close();
    trx = null;
    log.config("complete");
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 38 with PO

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

the class WPOSTable method loadTable.

//	loadTable
/**
	 *	Load Table from Object Array.
	 *  @param pos array of Persistent Objects
	 */
public void loadTable(PO[] pos) {
    int row = 0;
    int col = 0;
    // index into the PO array
    int poIndex = 0;
    String columnName;
    Object data;
    Class columnClass;
    if (m_layout == null) {
        throw new UnsupportedOperationException("Layout not defined");
    }
    //  Clear Table
    clearTable();
    for (poIndex = 0; poIndex < pos.length; poIndex++) {
        PO myPO = pos[poIndex];
        row = getRowCount();
        setRowCount(row + 1);
        for (col = 0; col < m_layout.length; col++) {
            columnName = m_layout[col].getColSQL();
            data = myPO.get_Value(columnName);
            if (data != null) {
                columnClass = m_layout[col].getColClass();
                if (isColumnClassMismatch(col, columnClass)) {
                    throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
                }
                if (columnClass == IDColumn.class) {
                    data = new IDColumn(((Integer) data).intValue());
                } else if (columnClass == Double.class) {
                    data = new Double(((BigDecimal) data).doubleValue());
                }
            }
            //  store
            getModel().setDataAt(data, row, col);
        }
    }
    autoSize();
    if (getShowTotals())
        addTotals(m_layout);
    // repaint the table
    this.repaint();
    logger.config("Row(array)=" + getRowCount());
    return;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ApplicationException(org.adempiere.webui.exception.ApplicationException) PO(org.compiere.model.PO)

Example 39 with PO

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

the class MRPApproval method createSupply.

// doIt
private void createSupply(MPPMRP mrp, String orderType) {
    PO document = null;
    if (MPPMRP.ORDERTYPE_MaterialRequisition.equals(orderType)) {
        if (getBusinessPartnerId() <= 0)
            throw new AdempiereException("@BPartnerNotFound@");
        document = createRequisition(mrp);
    }
    if (MPPMRP.ORDERTYPE_ManufacturingOrder.equals(orderType) && getResourcePlantId() > 0 && getBOMFormulaId() > 0 && getWorkflowId() > 0) {
        document = createManufacturingOrder(mrp);
    }
    if (MPPMRP.ORDERTYPE_DistributionOrder.equals(orderType) && getWarehouseinTransitId() > 0 && getShipperId() > 0 && getLocatorId() > 0 && getLocatorToId() > 0 && getBusinessPartnerId() > 0) {
        document = createDistributionOrder(mrp);
    }
    if (MPPMRP.ORDERTYPE_MaterialRequisition.equals(mrp.getOrderType()) && document != null && document.get_ID() > 0) {
        MRequisition requisition = (MRequisition) mrp.getM_Requisition();
        requisition.deleteEx(true);
    }
    if (MPPMRP.ORDERTYPE_ManufacturingOrder.equals(mrp.getOrderType()) && document != null && document.get_ID() > 0) {
        MPPOrder order = (MPPOrder) mrp.getPP_Order();
        order.deleteEx(true);
    }
    if (MPPMRP.ORDERTYPE_DistributionOrder.equals(mrp.getOrderType()) && document != null && document.get_ID() > 0) {
        MDDOrder order = (MDDOrder) mrp.getDD_Order();
        order.deleteEx(true);
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MDDOrder(org.eevolution.model.MDDOrder) MRequisition(org.compiere.model.MRequisition) MPPOrder(org.eevolution.model.MPPOrder) PO(org.compiere.model.PO)

Example 40 with PO

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

the class WDocActionPanel method dynInit.

/**
	 *	Dynamic Init - determine valid DocActions based on DocStatus for the different documents.
	 */
private void dynInit() {
    //
    Object Processing = gridTab.getValue("Processing");
    String OrderType = Env.getContext(Env.getCtx(), gridTab.getWindowNo(), "OrderType");
    String IsSOTrx = Env.getContext(Env.getCtx(), gridTab.getWindowNo(), "IsSOTrx");
    if (DocStatus == null) {
        //message.setText("*** ERROR ***");
        return;
    }
    logger.fine("DocStatus=" + DocStatus + ", DocAction=" + DocAction + ", OrderType=" + OrderType + ", IsSOTrx=" + IsSOTrx + ", Processing=" + Processing + ", AD_Table_ID=" + gridTab.getAD_Table_ID() + ", Record_ID=" + gridTab.getRecord_ID());
    int index = 0;
    if (lstDocAction.getSelectedItem() != null) {
        String selected = (lstDocAction.getSelectedItem().getValue()).toString();
        for (int i = 0; i < s_value.length && index == 0; i++) {
            if (s_value[i].equals(selected)) {
                index = i;
            }
        }
    }
    String[] options = new String[s_value.length];
    /**
		 * 	Check Existence of Workflow Acrivities
		 */
    String wfStatus = MWFActivity.getActiveInfo(Env.getCtx(), m_AD_Table_ID, gridTab.getRecord_ID());
    if (wfStatus != null) {
        FDialog.error(gridTab.getWindowNo(), this, "WFActiveForRecord", wfStatus);
        return;
    }
    //	Status Change
    if (!checkStatus(gridTab.getTableName(), gridTab.getRecord_ID(), DocStatus)) {
        FDialog.error(gridTab.getWindowNo(), this, "DocumentStatusChanged");
        return;
    }
    /*******************
		 *  General Actions
		 */
    String[] docActionHolder = new String[] { DocAction };
    index = DocumentEngine.getValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options);
    MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
    PO po = table.getPO(gridTab.getRecord_ID(), null);
    if (po instanceof DocOptions)
        index = ((DocOptions) po).customizeValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options, index);
    Integer doctypeId = (Integer) gridTab.getValue("C_DocType_ID");
    if (doctypeId == null || doctypeId.intValue() == 0) {
        doctypeId = (Integer) gridTab.getValue("C_DocTypeTarget_ID");
    }
    logger.fine("get doctype: " + doctypeId);
    if (doctypeId != null) {
        index = DocumentEngine.checkActionAccess(Env.getAD_Client_ID(Env.getCtx()), Env.getAD_Role_ID(Env.getCtx()), doctypeId, options, index);
    }
    DocAction = docActionHolder[0];
    /**
		 *	Fill actionCombo
		 */
    boolean firstadded = true;
    for (int i = 0; i < index; i++) {
        //	Serach for option and add it
        boolean added = false;
        for (int j = 0; j < s_value.length && !added; j++) {
            if (options[i].equals(s_value[j])) {
                Listitem newitem = lstDocAction.appendItem(s_name[j], s_value[j]);
                if (firstadded) {
                    // select by default the first added item - can be changed below
                    lstDocAction.setSelectedItem(newitem);
                    firstadded = false;
                }
                added = true;
            }
        }
    }
    // look if the current DocAction is within the list and assign it as selected if it exists
    List<Listitem> lst = (List<Listitem>) lstDocAction.getItems();
    for (Listitem item : lst) {
        String value = item.getValue().toString();
        if (DocAction.equals(value)) {
            lstDocAction.setSelectedItem(item);
            label.setValue(s_description[getSelectedIndex()]);
        }
    }
    //	setDefault
    if (//	If None, suggest closing
    DocAction.equals("--"))
        DocAction = DocumentEngine.ACTION_Close;
}
Also used : MTable(org.compiere.model.MTable) DocOptions(org.compiere.process.DocOptions) Listitem(org.zkoss.zul.Listitem) ArrayList(java.util.ArrayList) List(java.util.List) 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