Search in sources :

Example 11 with MDDOrder

use of org.eevolution.model.MDDOrder in project adempiere by adempiere.

the class ReplenishReportProduction method createDO.

//	Create Inventory Movements
/**
	 * 	Create Distribution Order
	 */
private void createDO() throws Exception {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MDDOrder order = 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 (X_T_Replenish replenish : replenishs) {
        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 (order == 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();
            order = new MDDOrder(getCtx(), 0, get_TrxName());
            order.setC_DocType_ID(p_C_DocType_ID);
            order.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            order.setAD_Org_ID(whSource.getAD_Org_ID());
            // Set Org Trx
            MOrg orgTrx = MOrg.get(getCtx(), wh.getAD_Org_ID());
            order.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
            int C_BPartner_ID = orgTrx.getLinkedC_BPartner_ID(get_TrxName());
            if (C_BPartner_ID == 0)
                throw new AdempiereUserError(Msg.translate(getCtx(), "C_BPartner_ID") + " @FillMandatory@ ");
            MBPartner bp = new MBPartner(getCtx(), C_BPartner_ID, get_TrxName());
            // Set BPartner Link to Org
            order.setBPartner(bp);
            order.setDateOrdered(new Timestamp(System.currentTimeMillis()));
            //order.setDatePromised(DatePromised);
            order.setDeliveryRule(MDDOrder.DELIVERYRULE_Availability);
            order.setDeliveryViaRule(MDDOrder.DELIVERYVIARULE_Delivery);
            order.setPriorityRule(MDDOrder.PRIORITYRULE_Medium);
            order.setIsInDispute(false);
            order.setIsApproved(false);
            order.setIsDropShip(false);
            order.setIsDelivered(false);
            order.setIsInTransit(false);
            order.setIsPrinted(false);
            order.setIsSelected(false);
            order.setIsSOTrx(false);
            // Warehouse in Transit
            MWarehouse[] whsInTransit = MWarehouse.getForOrg(getCtx(), whSource.getAD_Org_ID());
            for (MWarehouse whInTransit : whsInTransit) {
                if (whInTransit.isInTransit())
                    order.setM_Warehouse_ID(whInTransit.getM_Warehouse_ID());
            }
            if (order.getM_Warehouse_ID() == 0)
                throw new AdempiereUserError("Warehouse inTransit is @FillMandatory@ ");
            if (!order.save())
                return;
            log.fine(order.toString());
            noMoves++;
            info += " - " + order.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        int M_Locator_ID = whSource.getDefaultLocator().getM_Locator_ID();
        if (M_LocatorTo_ID == 0 || M_Locator_ID == 0)
            throw new AdempiereUserError(Msg.translate(getCtx(), "M_Locator_ID") + " @FillMandatory@ ");
        //	From: Look-up Storage
        /*MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
			MProductCategory pc = MProductCategory.get(getCtx(), product.getM_Product_Category_ID());
			String MMPolicy = pc.getMMPolicy();
			if (MMPolicy == null || MMPolicy.length() == 0)
				MMPolicy = client.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();
				//
				MDDOrderLine line = new MDDOrderLine(order);
				line.setM_Product_ID(replenish.getM_Product_ID());
				line.setQtyEntered(moveQty);
				if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
					line.setDescription("Total: " + replenish.getQtyToOrder());
				line.setM_Locator_ID(storage.getM_Locator_ID());		//	from
				line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
				line.setM_LocatorTo_ID(M_LocatorTo_ID);					//	to
				line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
				line.setIsInvoiced(false);
				line.save();
				//
				target = target.subtract(moveQty);
				if (target.signum() == 0)
					break;
			}*/
        MDDOrderLine line = new MDDOrderLine(order);
        line.setM_Product_ID(replenish.getM_Product_ID());
        line.setQty(replenish.getQtyToOrder());
        if (replenish.getQtyToOrder().compareTo(replenish.getQtyToOrder()) != 0)
            line.setDescription("Total: " + replenish.getQtyToOrder());
        //	from
        line.setM_Locator_ID(M_Locator_ID);
        line.setM_AttributeSetInstance_ID(0);
        //	to
        line.setM_LocatorTo_ID(M_LocatorTo_ID);
        line.setM_AttributeSetInstanceTo_ID(0);
        line.setIsInvoiced(false);
        line.save();
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner) Timestamp(java.sql.Timestamp) MWarehouse(org.compiere.model.MWarehouse) MClient(org.compiere.model.MClient) MDDOrderLine(org.eevolution.model.MDDOrderLine) MOrg(org.compiere.model.MOrg) X_T_Replenish(org.compiere.model.X_T_Replenish) MDDOrder(org.eevolution.model.MDDOrder)

Example 12 with MDDOrder

use of org.eevolution.model.MDDOrder in project adempiere by adempiere.

the class MRPSchedule method schedule.

// doIt
private void schedule(MPPMRP mrp) {
    if (!mrp.is_Changed())
        return;
    processRecords++;
    if (MPPMRP.ORDERTYPE_Forecast.equals(mrp.getOrderType())) {
        MForecastLine forecastLine = (MForecastLine) mrp.getM_ForecastLine();
        if (forecastLine != null) {
            forecastLine.setDatePromised(mrp.getDatePromised());
            forecastLine.setSalesRep_ID(mrp.getPlanner_ID());
            forecastLine.saveEx();
        }
    } else if (MPPMRP.ORDERTYPE_MaterialRequisition.equals(mrp.getOrderType())) {
        MRequisition requisition = (MRequisition) mrp.getM_Requisition();
        if (requisition != null) {
            requisition.setDateDoc(mrp.getDateStartSchedule());
            requisition.setDateRequired(mrp.getDatePromised());
            requisition.setAD_User_ID(mrp.getPlanner_ID());
            requisition.setPriorityRule(mrp.getPriority());
            requisition.saveEx();
        }
    } else if (MPPMRP.ORDERTYPE_ManufacturingOrder.equals(mrp.getOrderType())) {
        MPPOrder order = (MPPOrder) mrp.getPP_Order();
        if (order != null) {
            order.setDateStartSchedule(mrp.getDateStartSchedule());
            order.setDateFinishSchedule(mrp.getDateFinishSchedule());
            order.setDatePromised(mrp.getDatePromised());
            order.setPlanner_ID(mrp.getPlanner_ID());
            if (mrp.getPriority() != null)
                order.setPriorityRule(mrp.getPriority());
            order.setLine(lineNo);
            order.saveEx();
        }
    } else if (MPPMRP.ORDERTYPE_DistributionOrder.equals(mrp.getOrderType())) {
        MDDOrderLine orderLine = (MDDOrderLine) mrp.getDD_OrderLine();
        if (orderLine != null) {
            orderLine.setDateOrdered(mrp.getDateStartSchedule());
            orderLine.setDatePromised(mrp.getDatePromised());
            orderLine.saveEx();
            MDDOrder order = orderLine.getParent();
            order.setSalesRep_ID(mrp.getPlanner_ID());
            order.setPriorityRule(mrp.getPriority());
            order.saveEx();
        }
    } else if (MPPMRP.ORDERTYPE_SalesOrder.equals(mrp.getOrderType())) {
        MOrderLine orderLine = (MOrderLine) mrp.getC_OrderLine();
        if (orderLine != null) {
            orderLine.setDateOrdered(mrp.getDateStartSchedule());
            orderLine.setDatePromised(mrp.getDatePromised());
            orderLine.saveEx();
            MOrder order = orderLine.getParent();
            order.setSalesRep_ID(mrp.getPlanner_ID());
            order.setPriorityRule(mrp.getPriority());
            order.saveEx();
        }
    } else if (MPPMRP.ORDERTYPE_PurchaseOrder.equals(mrp.getOrderType())) {
        MOrderLine orderLine = (MOrderLine) mrp.getC_OrderLine();
        if (orderLine != null) {
            orderLine.setDateOrdered(mrp.getDateStartSchedule());
            orderLine.setDatePromised(mrp.getDatePromised());
            orderLine.saveEx();
            MOrder order = orderLine.getParent();
            order.setSalesRep_ID(mrp.getPlanner_ID());
            order.setPriorityRule(mrp.getPriority());
            order.saveEx();
        }
    }
}
Also used : MForecastLine(org.compiere.model.MForecastLine) MDDOrderLine(org.eevolution.model.MDDOrderLine) MOrder(org.compiere.model.MOrder) MDDOrder(org.eevolution.model.MDDOrder) MOrderLine(org.compiere.model.MOrderLine) MRequisition(org.compiere.model.MRequisition) MPPOrder(org.eevolution.model.MPPOrder)

Example 13 with MDDOrder

use of org.eevolution.model.MDDOrder 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 14 with MDDOrder

use of org.eevolution.model.MDDOrder in project adempiere by adempiere.

the class MRPApproval method executeDistributionOrderApproval.

private void executeDistributionOrderApproval(MPPMRP mrp) {
    MDDOrder order = (MDDOrder) mrp.getDD_Order();
    if (mrp.is_Changed()) {
        validateChanges(mrp, MPPMRP.COLUMNNAME_Priority, order, MDDOrder.COLUMNNAME_PriorityRule);
        order.saveEx();
        MDDOrderLine orderLine = (MDDOrderLine) mrp.getDD_OrderLine();
        orderLine.setQty(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "MRP_" + MPPMRP.COLUMNNAME_Qty));
        Timestamp datePromised = getSelectionAsTimestamp(mrp.getPP_MRP_ID(), MDDOrder.COLUMNNAME_DatePromised);
        if (datePromised != null)
            orderLine.setDatePromised(datePromised);
        orderLine.saveEx();
    }
    if (getShipperId() > 0)
        order.setM_Shipper_ID(getShipperId());
    order.processIt(DocAction.ACTION_Prepare);
    order.saveEx();
}
Also used : MDDOrderLine(org.eevolution.model.MDDOrderLine) MDDOrder(org.eevolution.model.MDDOrder) Timestamp(java.sql.Timestamp)

Aggregations

MDDOrder (org.eevolution.model.MDDOrder)14 MDDOrderLine (org.eevolution.model.MDDOrderLine)12 BigDecimal (java.math.BigDecimal)7 Timestamp (java.sql.Timestamp)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 MBPartner (org.compiere.model.MBPartner)6 MLocator (org.compiere.model.MLocator)5 MOrg (org.compiere.model.MOrg)5 MWarehouse (org.compiere.model.MWarehouse)5 MClient (org.compiere.model.MClient)4 MMovementLine (org.compiere.model.MMovementLine)4 MMovement (org.compiere.model.MMovement)3 MProduct (org.compiere.model.MProduct)3 MStorage (org.compiere.model.MStorage)3 Query (org.compiere.model.Query)3 ResultSet (java.sql.ResultSet)2 Properties (java.util.Properties)2 MProductCategory (org.compiere.model.MProductCategory)2 MRequisition (org.compiere.model.MRequisition)2 X_T_Replenish (org.compiere.model.X_T_Replenish)2