Search in sources :

Example 1 with MDDNetworkDistributionLine

use of org.eevolution.model.MDDNetworkDistributionLine 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

BigDecimal (java.math.BigDecimal)1 MBPartner (org.compiere.model.MBPartner)1 MLocator (org.compiere.model.MLocator)1 MOrg (org.compiere.model.MOrg)1 MWarehouse (org.compiere.model.MWarehouse)1 Query (org.compiere.model.Query)1 MDDNetworkDistribution (org.eevolution.model.MDDNetworkDistribution)1 MDDNetworkDistributionLine (org.eevolution.model.MDDNetworkDistributionLine)1 MDDOrder (org.eevolution.model.MDDOrder)1 MDDOrderLine (org.eevolution.model.MDDOrderLine)1 MPPMRP (org.eevolution.model.MPPMRP)1