Search in sources :

Example 16 with MWarehouse

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

the class ReplenishReport method createMovements.

//	createRequisition
/**
	 * 	Create Inventory Movements
	 */
private void createMovements() {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MMovement move = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
    for (int i = 0; i < replenishs.length; i++) {
        X_T_Replenish replenish = replenishs[i];
        if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
            whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
            client = MClient.get(getCtx(), whSource.getAD_Client_ID());
        //
        if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
            M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
            M_Warehouse_ID = replenish.getM_Warehouse_ID();
            move = new MMovement(getCtx(), 0, get_TrxName());
            move.setC_DocType_ID(p_C_DocType_ID);
            move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            move.setAD_Org_ID(whSource.getAD_Org_ID());
            if (!move.save())
                return;
            log.fine(move.toString());
            noMoves++;
            info += " - " + move.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        //	From: Look-up Storage
        MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
        String MMPolicy = product.getMMPolicy();
        MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
        //
        BigDecimal target = replenish.getQtyToOrder();
        for (int j = 0; j < storages.length; j++) {
            MStorage storage = storages[j];
            if (storage.getQtyOnHand().signum() <= 0)
                continue;
            BigDecimal moveQty = target;
            if (storage.getQtyOnHand().compareTo(moveQty) < 0)
                moveQty = storage.getQtyOnHand();
            //
            MMovementLine line = new MMovementLine(move);
            line.setM_Product_ID(replenish.getM_Product_ID());
            line.setMovementQty(moveQty);
            if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
                line.setDescription("Total: " + replenish.getQtyToOrder());
            //	from
            line.setM_Locator_ID(storage.getM_Locator_ID());
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
            //	to
            line.setM_LocatorTo_ID(M_LocatorTo_ID);
            line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
            line.saveEx();
            //
            target = target.subtract(moveQty);
            if (target.signum() == 0)
                break;
        }
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : MProduct(org.compiere.model.MProduct) X_T_Replenish(org.compiere.model.X_T_Replenish) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement) MStorage(org.compiere.model.MStorage) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MClient(org.compiere.model.MClient)

Example 17 with MWarehouse

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

the class ReplenishReport method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message 
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("M_Warehouse_ID=" + p_M_Warehouse_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + " - ReplenishmentCreate=" + p_ReplenishmentCreate + ", C_DocType_ID=" + p_C_DocType_ID);
    if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0)
        throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@");
    MWarehouse wh = MWarehouse.get(getCtx(), p_M_Warehouse_ID);
    if (wh.get_ID() == 0)
        throw new AdempiereSystemError("@FillMandatory@ @M_Warehouse_ID@");
    //
    prepareTable();
    fillTable(wh);
    //
    if (p_ReplenishmentCreate == null)
        return "OK";
    //
    MDocType dt = MDocType.get(getCtx(), p_C_DocType_ID);
    if (!dt.getDocBaseType().equals(p_ReplenishmentCreate))
        throw new AdempiereSystemError("@C_DocType_ID@=" + dt.getName() + " <> " + p_ReplenishmentCreate);
    //
    if (p_ReplenishmentCreate.equals("POO"))
        createPO();
    else if (p_ReplenishmentCreate.equals("POR"))
        createRequisition();
    else if (p_ReplenishmentCreate.equals("MMM"))
        createMovements();
    else if (p_ReplenishmentCreate.equals("DOO"))
        createDO();
    return m_info;
}
Also used : MDocType(org.compiere.model.MDocType) AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MWarehouse(org.compiere.model.MWarehouse)

Example 18 with MWarehouse

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

the class InventoryUtil method getCreateWarehouse.

/**
	 * Helper Method : Create Warehouse
	 */
public static MWarehouse getCreateWarehouse(int AD_Org_ID, String value) {
    if (AD_Org_ID <= 0)
        AD_Org_ID = getFirst_Org_ID();
    Properties ctx = Env.getCtx();
    final String whereClause = "AD_Org_ID=? AND Value=?";
    MWarehouse wh = new Query(ctx, I_M_Warehouse.Table_Name, whereClause, null).setParameters(AD_Org_ID, value).setClient_ID().firstOnly();
    if (wh != null)
        return wh;
    wh = new MWarehouse(ctx, 0, null);
    wh.setAD_Org_ID(AD_Org_ID);
    wh.setValue(value);
    wh.setName(value);
    MLocation loc = new MLocation(ctx, 0, null);
    loc.saveEx();
    wh.setC_Location_ID(loc.get_ID());
    wh.saveEx();
    return wh;
}
Also used : Query(org.compiere.model.Query) Properties(java.util.Properties) MLocation(org.compiere.model.MLocation) MWarehouse(org.compiere.model.MWarehouse)

Example 19 with MWarehouse

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

the class MRP method doIt.

protected String doIt() throws Exception {
    parameters = new ArrayList<Object>();
    dd_order_id_cache.clear();
    partner_cache.clear();
    StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType + "=? AND AD_Client_ID=?");
    parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant);
    parameters.add(getAD_Client_ID());
    if (getPlant_ID() > 0) {
        whereClause.append(" AND " + MResource.COLUMNNAME_S_Resource_ID + "=?");
        parameters.add(getPlant_ID());
    }
    List<MResource> plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
    if (plants == null || plants.size() <= 0)
        return MRefList.getListName(getCtx(), MResource.MANUFACTURINGRESOURCETYPE_AD_Reference_ID, "PT") + " @S_Resource_ID@ @NotFound@";
    for (MResource plant : plants) {
        log.info("Run MRP to Plant: " + plant.getName());
        this.Planning_Horizon = TimeUtil.addDays(getToday(), plant.getPlanningHorizon());
        parameters = new ArrayList<Object>();
        whereClause = new StringBuffer("AD_Client_ID=?");
        parameters.add(getAD_Client_ID());
        if (getAD_Org_ID() > 0) {
            whereClause.append(" AND AD_Org_ID=?");
            parameters.add(getAD_Org_ID());
        }
        List<MOrg> orgList = new Query(getCtx(), MOrg.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
        for (MOrg org : orgList) {
            // Set Default Document Type To Requisition
            int AD_User_ID = Env.getAD_User_ID(getCtx());
            docTypeReq_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_PurchaseRequisition, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            docTypeMO_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_ManufacturingOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            docTypeMF_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_MaintenanceOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            docTypeDO_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            log.info("Run MRP to Organization: " + org.getName());
            MWarehouse[] ws;
            if (getM_Warehouse_ID() <= 0) {
                ws = MWarehouse.getForOrg(getCtx(), org.getAD_Org_ID());
            } else {
                ws = new MWarehouse[] { MWarehouse.get(getCtx(), getM_Warehouse_ID()) };
            }
            //
            for (MWarehouse w : ws) {
                // remove using DRP should be executed
                //if(plant.getM_Warehouse_ID() == w.getM_Warehouse_ID() && isRequiredDRP())
                //	continue;
                log.info("Run MRP to Wharehouse: " + w.getName());
                runMRP(getAD_Client_ID(), org.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
                StringBuffer resultMsg = new StringBuffer();
                resultMsg.append("<br> <b> @AD_Org_ID@: </b>" + org.getName());
                resultMsg.append("<b>, @M_Warehouse_ID@: </b>" + w.getName());
                resultMsg.append("<b>, @S_Resource_ID@: </b>" + plant.getName());
                resultMsg.append("<hr>");
                resultMsg.append("<br><b>@PP_Order_ID@:</b> " + count_MO);
                resultMsg.append("<br><b>@DD_Order_ID@:</b> " + count_DO);
                resultMsg.append("<br><b>@M_Requisition_ID@:</b> " + count_MR);
                resultMsg.append("<br><b>@AD_Note_ID@:</b> " + count_Msg);
                count_MO = 0;
                count_MR = 0;
                count_DO = 0;
                count_Msg = 0;
                addLog("");
                addLog(resultMsg.toString());
            }
        //resultMsg.append("<br>finish MRP to Organization " +org.getName());
        }
    }
    //
    return "";
}
Also used : MResource(org.compiere.model.MResource) MOrg(org.compiere.model.MOrg) Query(org.compiere.model.Query) MWarehouse(org.compiere.model.MWarehouse)

Example 20 with MWarehouse

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

the class MRP method createDDOrder.

protected void createDDOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product, BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule, String trxName) throws AdempiereException, SQLException {
    //TODO vpj-cd I need to create logic for DRP-040 Shipment Due  Action Notice
    //Indicates that a shipment for a Order Distribution is due. 
    // Action should be taken at the source warehouse to ensure that the order is received on time.
    //TODO vpj-cd I need to create logic for DRP-050 Shipment Pas Due  Action Notice
    //Indicates that a shipment for a Order Distribution is past due. You should either delay the orders created the requirement for the product 
    //or expedite them when the product does arrive.
    //Setting DRP Change net Update out the model validator
    MPPMRP.setIsRequired(m_product_planning, MPPProductPlanning.COLUMNNAME_IsRequiredDRP, false, trxName);
    if (m_product_planning.getDD_NetworkDistribution_ID() == 0) {
        //Indicates that the Product Planning Data for this product does not specify a valid network distribution.
        createMRPNote("DRP-060", AD_Org_ID, PP_MRP_ID, product, (String) null, null, null, trxName);
    }
    //TODO: Create functionality for Valid form and Valid To for an Network Distribution
    MDDNetworkDistribution network = MDDNetworkDistribution.get(getCtx(), m_product_planning.getDD_NetworkDistribution_ID());
    MDDNetworkDistributionLine[] network_lines = network.getLines(m_product_planning.getM_Warehouse_ID());
    int M_Shipper_ID = 0;
    MDDOrder order = null;
    Integer DD_Order_ID = 0;
    for (MDDNetworkDistributionLine network_line : network_lines) {
        if (network_line.getM_Shipper_ID() == 0) {
            String comment = Msg.translate(getCtx(), MDDNetworkDistribution.COLUMNNAME_Name) + " : " + network.getName();
            createMRPNote("DRP-030", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get supply source warehouse and locator
        MWarehouse source = new MWarehouse(getCtx(), network_line.getM_WarehouseSource_ID(), trxName);
        MLocator locator = MLocator.getDefault(source);
        if (locator == null || locator.getM_Locator_ID() <= 0) {
            String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
            createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get supply target warehouse and locator
        MWarehouse target = new MWarehouse(getCtx(), network_line.getM_Warehouse_ID(), trxName);
        MLocator locator_to = MLocator.getDefault(target);
        if (locator_to == null || locator_to.getM_Locator_ID() <= 0) {
            String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
            createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get the transfer time
        BigDecimal transferTime = network_line.getTransferTime();
        if (transferTime.compareTo(Env.ZERO) <= 0) {
            transferTime = m_product_planning.getTransferTime();
        }
        if (locator == null || locator_to == null) {
            String comment = Msg.translate(getCtx(), MDDNetworkDistributionLine.COLUMNNAME_M_WarehouseSource_ID) + " : " + source.getName();
            createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get the warehouse in transit
        MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), source.getAD_Org_ID());
        if (wsts == null || wsts.length == 0) {
            String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
            createMRPNote("DRP-010", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        if (M_Shipper_ID != network_line.getM_Shipper_ID()) {
            //Org Must be linked to BPartner
            MOrg org = MOrg.get(getCtx(), locator_to.getAD_Org_ID());
            int C_BPartner_ID = org.getLinkedC_BPartner_ID(trxName);
            if (C_BPartner_ID == 0) {
                String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
                createMRPNote("DRP-020", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
                continue;
            }
            MBPartner bp = getBPartner(C_BPartner_ID);
            // Try found some order with Shipper , Business Partner and Doc Status = Draft 
            // Consolidate the demand in a single order for each Shipper , Business Partner , DemandDateStartSchedule
            DD_Order_ID = getDDOrder_ID(AD_Org_ID, wsts[0].get_ID(), network_line.getM_Shipper_ID(), bp.getC_BPartner_ID(), TimeUtil.getDay(DemandDateStartSchedule.getTime()), trxName);
            if (DD_Order_ID <= 0) {
                order = new MDDOrder(getCtx(), 0, trxName);
                order.setAD_Org_ID(target.getAD_Org_ID());
                order.setC_BPartner_ID(C_BPartner_ID);
                order.setAD_User_ID(bp.getPrimaryAD_User_ID());
                order.setC_DocType_ID(docTypeDO_ID);
                order.setM_Warehouse_ID(wsts[0].get_ID());
                order.setDocAction(MDDOrder.DOCACTION_Complete);
                order.setDateOrdered(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(transferTime)).negate().intValueExact()));
                order.setDatePromised(DemandDateStartSchedule);
                order.setM_Shipper_ID(network_line.getM_Shipper_ID());
                order.setIsInDispute(false);
                order.setIsInTransit(false);
                order.setSalesRep_ID(m_product_planning.getPlanner_ID());
                order.setProcessed(false);
                order.setProcessing(false);
                order.saveEx();
                order.addDescription(Msg.parseTranslation(getCtx(), "@DD_Order_ID@ @DocumentNo@ " + order.getDocumentNo() + " @Generate@ @from@ " + getName()));
                order.saveEx();
                DD_Order_ID = order.get_ID();
                String key = order.getAD_Org_ID() + "#" + order.getM_Warehouse_ID() + "#" + network_line.getM_Shipper_ID() + "#" + C_BPartner_ID + "#" + TimeUtil.getDay(DemandDateStartSchedule.getTime()) + "DR";
                dd_order_id_cache.put(key, DD_Order_ID);
            } else {
                order = new MDDOrder(getCtx(), DD_Order_ID, trxName);
            }
            M_Shipper_ID = network_line.getM_Shipper_ID();
        }
        BigDecimal QtyOrdered = QtyPlanned.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED);
        MDDOrderLine oline = new MDDOrderLine(getCtx(), 0, trxName);
        oline.setDD_Order_ID(order.getDD_Order_ID());
        oline.setAD_Org_ID(target.getAD_Org_ID());
        oline.setM_Locator_ID(locator.getM_Locator_ID());
        oline.setM_LocatorTo_ID(locator_to.getM_Locator_ID());
        oline.setM_Product_ID(m_product_planning.getM_Product_ID());
        oline.setDateOrdered(order.getDateOrdered());
        oline.setDatePromised(DemandDateStartSchedule);
        oline.setQtyEntered(QtyOrdered);
        oline.setQtyOrdered(QtyOrdered);
        oline.setTargetQty(MPPMRP.getQtyReserved(getCtx(), target.getM_Warehouse_ID(), m_product_planning.getM_Product_ID(), DemandDateStartSchedule, trxName));
        oline.setIsInvoiced(false);
        oline.saveEx();
        // Set Correct Dates for Plan
        final String whereClause = MPPMRP.COLUMNNAME_DD_OrderLine_ID + "=?";
        List<MPPMRP> mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, trxName).setParameters(new Object[] { oline.getDD_OrderLine_ID() }).list();
        for (MPPMRP mrp : mrpList) {
            mrp.setDateOrdered(getToday());
            mrp.setDateOrdered(mrp.getDD_Order().getDateOrdered());
            mrp.setDateStartSchedule(mrp.getDateOrdered());
            mrp.setDatePromised(DemandDateStartSchedule);
            mrp.setDateFinishSchedule(DemandDateStartSchedule);
            mrp.saveEx();
            if (MPPMRP.TYPEMRP_Supply.equals(mrp.getTypeMRP()))
                supplies.put(mrp.get_ID(), mrp.getQty());
        }
        count_DO += 1;
    }
}
Also used : MDDNetworkDistributionLine(org.eevolution.model.MDDNetworkDistributionLine) Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner) MPPMRP(org.eevolution.model.MPPMRP) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MDDNetworkDistribution(org.eevolution.model.MDDNetworkDistribution) MDDOrderLine(org.eevolution.model.MDDOrderLine) MOrg(org.compiere.model.MOrg) MLocator(org.compiere.model.MLocator) MDDOrder(org.eevolution.model.MDDOrder)

Aggregations

MWarehouse (org.compiere.model.MWarehouse)39 MLocator (org.compiere.model.MLocator)12 BigDecimal (java.math.BigDecimal)9 X_T_Replenish (org.compiere.model.X_T_Replenish)9 MBPartner (org.compiere.model.MBPartner)8 MOrg (org.compiere.model.MOrg)8 Query (org.compiere.model.Query)8 MProduct (org.compiere.model.MProduct)6 MClient (org.compiere.model.MClient)5 AdempiereUserError (org.compiere.util.AdempiereUserError)5 MDDOrder (org.eevolution.model.MDDOrder)5 MDDOrderLine (org.eevolution.model.MDDOrderLine)5 MOrder (org.compiere.model.MOrder)4 MStorage (org.compiere.model.MStorage)4 Properties (java.util.Properties)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MLocation (org.compiere.model.MLocation)3 MMovement (org.compiere.model.MMovement)3 MMovementLine (org.compiere.model.MMovementLine)3 MOrderLine (org.compiere.model.MOrderLine)3