Search in sources :

Example 16 with MLocator

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

the class MRPApproval method createDistributionOrder.

private MDDOrder createDistributionOrder(MPPMRP mrp) {
    MLocator locatorFrom = MLocator.get(mrp.getCtx(), getLocatorId());
    MLocator locatorTo = MLocator.get(mrp.getCtx(), getLocatorToId());
    int docTypeId = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder, locatorTo.getAD_Org_ID(), Env.getAD_User_ID(getCtx()), get_TrxName());
    MBPartner partner = MBPartner.get(mrp.getCtx(), getBusinessPartnerId());
    MDDOrder order = new MDDOrder(getCtx(), 0, get_TrxName());
    order.setAD_Org_ID(mrp.getAD_Org_ID());
    order.addDescription("Generated by MRP");
    order.setC_BPartner_ID(getBusinessPartnerId());
    order.setAD_User_ID(partner.getPrimaryAD_User_ID());
    order.setC_DocType_ID(docTypeId);
    order.setM_Warehouse_ID(getWarehouseinTransitId());
    if (getReferenceNo() != null)
        order.setPOReference(getReferenceNo());
    order.setDocStatus(MDDOrder.DOCSTATUS_Drafted);
    order.setDocAction(MDDOrder.DOCACTION_Complete);
    order.setDateOrdered(mrp.getDateFinishSchedule());
    order.setDatePromised(mrp.getDatePromised());
    order.setM_Shipper_ID(getShipperId());
    if (getPriority() != null)
        order.setPriorityRule(getPriority());
    order.setIsInDispute(false);
    order.setIsInTransit(false);
    order.setSalesRep_ID(mrp.getPlanner_ID());
    order.saveEx();
    MDDOrderLine orderLine = new MDDOrderLine(getCtx(), 0, get_TrxName());
    orderLine.setDD_Order_ID(order.getDD_Order_ID());
    orderLine.setAD_Org_ID(locatorTo.getAD_Org_ID());
    orderLine.setM_Locator_ID(locatorFrom.getM_Locator_ID());
    orderLine.setM_LocatorTo_ID(locatorTo.getM_Locator_ID());
    orderLine.setM_Product_ID(mrp.getM_Product_ID());
    orderLine.setDateOrdered(order.getDateOrdered());
    orderLine.setDatePromised(mrp.getDatePromised());
    orderLine.setQtyEntered(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "MRP_" + MPPMRP.COLUMNNAME_Qty));
    orderLine.setQtyOrdered(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "MRP_" + MPPMRP.COLUMNNAME_Qty));
    orderLine.setConfirmedQty(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "DL_" + MDDOrderLine.COLUMNNAME_ConfirmedQty));
    orderLine.setTargetQty(MPPMRP.getQtyReserved(getCtx(), locatorTo.getM_Warehouse_ID(), mrp.getM_Product_ID(), mrp.getDateStartSchedule(), get_TrxName()));
    orderLine.setIsInvoiced(false);
    orderLine.saveEx();
    order.processIt(DocAction.ACTION_Prepare);
    order.saveEx();
    return order;
}
Also used : MDDOrderLine(org.eevolution.model.MDDOrderLine) MLocator(org.compiere.model.MLocator) MBPartner(org.compiere.model.MBPartner) MDDOrder(org.eevolution.model.MDDOrder)

Example 17 with MLocator

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

the class BPartnerOrgLink method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (text with variables)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("C_BPartner_ID=" + p_C_BPartner_ID + ", AD_Org_ID=" + p_AD_Org_ID + ", AD_OrgType_ID=" + p_AD_OrgType_ID + ", AD_Role_ID=" + p_AD_Role_ID);
    if (p_C_BPartner_ID == 0)
        throw new AdempiereUserError("No Business Partner ID");
    MBPartner bp = new MBPartner(getCtx(), p_C_BPartner_ID, get_TrxName());
    if (bp.get_ID() == 0)
        throw new AdempiereUserError("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID);
    //	BP Location
    MBPartnerLocation[] locs = bp.getLocations(false);
    if (locs == null || locs.length == 0)
        throw new IllegalArgumentException("Business Partner has no Location");
    //	Location
    int C_Location_ID = locs[0].getC_Location_ID();
    if (C_Location_ID == 0)
        throw new IllegalArgumentException("Business Partner Location has no Address");
    //	Create Org
    boolean newOrg = p_AD_Org_ID == 0;
    MOrg org = new MOrg(getCtx(), p_AD_Org_ID, get_TrxName());
    if (newOrg) {
        org.setValue(bp.getValue());
        org.setName(bp.getName());
        org.setDescription(bp.getDescription());
        if (!org.save())
            throw new Exception("Organization not saved");
    } else //	check if linked to already
    {
        int C_BPartner_ID = org.getLinkedC_BPartner_ID(get_TrxName());
        if (C_BPartner_ID > 0)
            throw new IllegalArgumentException("Organization '" + org.getName() + "' already linked (to C_BPartner_ID=" + C_BPartner_ID + ")");
    }
    p_AD_Org_ID = org.getAD_Org_ID();
    //	Update Org Info
    MOrgInfo oInfo = org.getInfo();
    oInfo.setAD_OrgType_ID(p_AD_OrgType_ID);
    if (newOrg)
        oInfo.setC_Location_ID(C_Location_ID);
    //	Create Warehouse
    MWarehouse wh = null;
    if (!newOrg) {
        MWarehouse[] whs = MWarehouse.getForOrg(getCtx(), p_AD_Org_ID);
        if (whs != null && whs.length > 0)
            //	pick first
            wh = whs[0];
    }
    //	New Warehouse
    if (wh == null) {
        wh = new MWarehouse(org);
        if (!wh.save(get_TrxName()))
            throw new Exception("Warehouse not saved");
    }
    //	Create Locator
    MLocator mLoc = wh.getDefaultLocator();
    if (mLoc == null) {
        mLoc = new MLocator(wh, "Standard");
        mLoc.setIsDefault(true);
        mLoc.save(get_TrxName());
    }
    //	Update/Save Org Info
    oInfo.setM_Warehouse_ID(wh.getM_Warehouse_ID());
    if (!oInfo.save(get_TrxName()))
        throw new Exception("Organization Info not saved");
    //	Update BPartner
    bp.setAD_OrgBP_ID(p_AD_Org_ID);
    if (bp.getAD_Org_ID() != 0)
        //	Shared BPartner
        bp.setClientOrg(bp.getAD_Client_ID(), 0);
    //	Save BP
    if (!bp.save())
        throw new Exception("Business Partner not updated");
    //	Limit to specific Role
    if (p_AD_Role_ID != 0) {
        boolean found = false;
        MRoleOrgAccess[] orgAccesses = MRoleOrgAccess.getOfOrg(getCtx(), p_AD_Org_ID);
        //	delete all accesses except the specific
        for (int i = 0; i < orgAccesses.length; i++) {
            if (orgAccesses[i].getAD_Role_ID() == p_AD_Role_ID)
                found = true;
            else
                orgAccesses[i].delete(true);
        }
        //	create access
        if (!found) {
            MRoleOrgAccess orgAccess = new MRoleOrgAccess(org, p_AD_Role_ID);
            orgAccess.save(get_TrxName());
        }
    }
    //	Reset Client Role
    MRole.getDefault(getCtx(), true);
    return "Business Partner - Organization Link created";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner) MWarehouse(org.compiere.model.MWarehouse) MBPartnerLocation(org.compiere.model.MBPartnerLocation) MOrg(org.compiere.model.MOrg) MLocator(org.compiere.model.MLocator) MOrgInfo(org.compiere.model.MOrgInfo) MRoleOrgAccess(org.compiere.model.MRoleOrgAccess)

Example 18 with MLocator

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

the class CreateFromShipment method getLocatorKeyNamePair.

/**
	 * Get KeyNamePair for Locator.
	 * If no locator specified or the specified locator is not valid (e.g. warehouse not match),
	 * a default one will be used.
	 * @param M_Locator_ID
	 * @return KeyNamePair
	 */
protected KeyNamePair getLocatorKeyNamePair(int M_Locator_ID) {
    MLocator locator = null;
    // Load desired Locator
    if (M_Locator_ID > 0) {
        locator = MLocator.get(Env.getCtx(), M_Locator_ID);
        // Validate warehouse
        if (locator != null && locator.getM_Warehouse_ID() != getM_Warehouse_ID()) {
            locator = null;
        }
    }
    // Try to use default locator from Order Warehouse
    if (locator == null && p_order != null && p_order.getM_Warehouse_ID() == getM_Warehouse_ID()) {
        MWarehouse wh = MWarehouse.get(Env.getCtx(), p_order.getM_Warehouse_ID());
        if (wh != null) {
            locator = wh.getDefaultLocator();
        }
    }
    // Try to get from locator field
    if (locator == null) {
        if (defaultLocator_ID > 0) {
            locator = MLocator.get(Env.getCtx(), defaultLocator_ID);
        }
    }
    // Validate Warehouse
    if (locator == null || locator.getM_Warehouse_ID() != getM_Warehouse_ID()) {
        locator = MWarehouse.get(Env.getCtx(), getM_Warehouse_ID()).getDefaultLocator();
    }
    KeyNamePair pp = null;
    if (locator != null) {
        pp = new KeyNamePair(locator.get_ID(), locator.getValue());
    }
    return pp;
}
Also used : MLocator(org.compiere.model.MLocator) KeyNamePair(org.compiere.util.KeyNamePair) MWarehouse(org.compiere.model.MWarehouse)

Example 19 with MLocator

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

the class HTMLMessenger method getStorageInfo.

public String getStorageInfo(MProduct p, MAttributeSetInstance asi) {
    StorageReasoner mr = new StorageReasoner();
    int[] ids = mr.getPOIDs(MLocator.Table_Name, null, null);
    MWarehouse warehouse = null;
    MStorage storage = null;
    MLocator locator = null;
    StringBuffer sb = new StringBuffer(STORAGE_HEADER_INFO_PATTERN);
    Object[] obj = null;
    BigDecimal sumQtyOnHand = BigDecimal.ZERO;
    BigDecimal sumQtyReserved = BigDecimal.ZERO;
    BigDecimal sumQtyOrdered = BigDecimal.ZERO;
    int count = 0;
    for (int i = 0; i < ids.length; i++) {
        storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null);
        if (storage == null) {
            continue;
        }
        count++;
        warehouse = new MWarehouse(Env.getCtx(), storage.getM_Warehouse_ID(), null);
        locator = new MLocator(Env.getCtx(), storage.getM_Locator_ID(), null);
        sumQtyOnHand = sumQtyOnHand.add(storage.getQtyOnHand());
        sumQtyReserved = sumQtyReserved.add(storage.getQtyReserved());
        sumQtyOrdered = sumQtyOrdered.add(storage.getQtyOrdered());
        // the quantities of specific locator
        obj = new Object[] { locator.getX() + " - " + locator.getY() + " - " + locator.getZ(), warehouse.getName(), storage.getQtyOnHand(), storage.getQtyReserved(), storage.getQtyOrdered(), storage.getQtyOnHand().subtract(storage.getQtyReserved()) };
        sb.append(MessageFormat.format(STORAGE_LINE_INFO_PATTERN, obj));
    }
    // the sum of the single quantities, if there is more than one line
    if (count > 1) {
        obj = new Object[] { sumQtyOnHand, sumQtyReserved, sumQtyOrdered, sumQtyOnHand.subtract(sumQtyReserved) };
        sb.append(MessageFormat.format(STORAGE_SUM_LINE_INFO_PATTERN, obj));
    }
    double available = sumQtyOnHand.subtract(sumQtyReserved).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    if (count == 0 || (available <= 0.00d)) {
        sb.append(MessageFormat.format(STORAGE_NOINVENTORY_INFO_PATTERN, obj));
    }
    sb.append(STORAGE_FOOTER_INFO_PATTERN);
    return sb.toString();
}
Also used : MLocator(org.compiere.model.MLocator) StorageReasoner(org.eevolution.model.reasoner.StorageReasoner) MStorage(org.compiere.model.MStorage) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal)

Example 20 with MLocator

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

the class MPPMRP method DD_OrderLine.

/**
	 * Create MRP record based in Distribution Order Line
	 * @param MDDOrderLine Distribution Order Line
	 */
public static void DD_OrderLine(MDDOrderLine ol) {
    String trxName = ol.get_TrxName();
    Properties m_ctx = ol.getCtx();
    //
    MPPMRP mrp = getQuery(ol, TYPEMRP_Demand, ORDERTYPE_DistributionOrder).firstOnly();
    MLocator source = MLocator.get(m_ctx, ol.getM_Locator_ID());
    MLocator target = MLocator.get(m_ctx, ol.getM_LocatorTo_ID());
    if (mrp != null) {
        mrp.setAD_Org_ID(source.getAD_Org_ID());
        mrp.setName("MRP");
        mrp.setDD_Order(ol.getParent());
        mrp.setDescription(ol.getDescription());
        mrp.setDatePromised(ol.getDatePromised());
        mrp.setDateOrdered(ol.getDateOrdered());
        mrp.setDateStartSchedule(ol.getDateOrdered());
        mrp.setM_Warehouse_ID(source.getM_Warehouse_ID());
        mrp.setM_Product_ID(ol.getM_Product_ID());
        mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
        mrp.saveEx();
    } else {
        mrp = new MPPMRP(m_ctx, 0, trxName);
        mrp.setAD_Org_ID(source.getAD_Org_ID());
        mrp.setName("MRP");
        mrp.setDescription(ol.getDescription());
        mrp.setDD_Order(ol.getParent());
        mrp.setDD_OrderLine_ID(ol.getDD_OrderLine_ID());
        mrp.setDatePromised(ol.getDatePromised());
        mrp.setDateOrdered(ol.getDateOrdered());
        mrp.setDateStartSchedule(ol.getDateOrdered());
        mrp.setM_Warehouse_ID(source.getM_Warehouse_ID());
        mrp.setM_Product_ID(ol.getM_Product_ID());
        mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
        mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder);
        mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
        mrp.saveEx();
    }
    mrp = getQuery(ol, TYPEMRP_Supply, ORDERTYPE_DistributionOrder).firstOnly();
    if (mrp != null) {
        mrp.setAD_Org_ID(target.getAD_Org_ID());
        mrp.setName("MRP");
        mrp.setDD_Order(ol.getParent());
        mrp.setDescription(ol.getDescription());
        mrp.setDatePromised(ol.getDatePromised());
        mrp.setDateOrdered(ol.getDateOrdered());
        mrp.setM_Product_ID(ol.getM_Product_ID());
        mrp.setM_Warehouse_ID(target.getM_Warehouse_ID());
        mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
        mrp.saveEx();
    } else {
        mrp = new MPPMRP(m_ctx, 0, trxName);
        mrp.setAD_Org_ID(target.getAD_Org_ID());
        mrp.setName("MRP");
        mrp.setDescription(ol.getDescription());
        mrp.setDD_Order(ol.getParent());
        mrp.setDD_OrderLine_ID(ol.getDD_OrderLine_ID());
        mrp.setDatePromised(ol.getDatePromised());
        mrp.setDateOrdered(ol.getDateOrdered());
        mrp.setM_Product_ID(ol.getM_Product_ID());
        mrp.setM_Warehouse_ID(target.getM_Warehouse_ID());
        mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
        mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder);
        mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
        mrp.saveEx();
    }
    return;
}
Also used : MLocator(org.compiere.model.MLocator) Properties(java.util.Properties)

Aggregations

MLocator (org.compiere.model.MLocator)49 MProduct (org.compiere.model.MProduct)18 BigDecimal (java.math.BigDecimal)16 MWarehouse (org.compiere.model.MWarehouse)12 MStorage (org.compiere.model.MStorage)9 ArrayList (java.util.ArrayList)8 Properties (java.util.Properties)8 Query (org.compiere.model.Query)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 MMovementLine (org.compiere.model.MMovementLine)6 KeyNamePair (org.compiere.util.KeyNamePair)6 ResultSet (java.sql.ResultSet)5 Timestamp (java.sql.Timestamp)5 MBPartner (org.compiere.model.MBPartner)5 MMovement (org.compiere.model.MMovement)5 MOrderLine (org.compiere.model.MOrderLine)5 MDDOrderLine (org.eevolution.model.MDDOrderLine)5 ListItem (org.adempiere.webui.component.ListItem)4 MDDOrder (org.eevolution.model.MDDOrder)4 PreparedStatement (java.sql.PreparedStatement)3