Search in sources :

Example 31 with MLocator

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

the class VComboBox method setValue.

/**
	 *  Common Setup
	 *
	private void common_init()
	{
		LookAndFeel.installColorsAndFont(this, "TextField.background", "TextField.foreground", "TextField.font");
		setForeground(AdempierePLAF.getTextColor_Normal());
		setBackground(AdempierePLAF.getFieldBackground_Normal());
		setPreferredSize(s_text.getPreferredSize());
	//	this.setKeySelectionManager(new ComboSelectionManager());
	}   //  common_init

	/** Reference Field         *
	private static  JTextField  s_text = new JTextField(VTextField.DISPLAY_SIZE);

	/**
	 *	Set Selected Item to key.
	 *		Find key value in list
	 *  @param key
	 */
public void setValue(Object key) {
    if (key == null) {
        this.setSelectedIndex(-1);
        return;
    }
    ComboBoxModel model = getModel();
    int size = model.getSize();
    for (int i = 0; i < size; i++) {
        Object element = model.getElementAt(i);
        String ID = null;
        if (element instanceof NamePair)
            ID = ((NamePair) element).getID();
        else if (element instanceof MLocator)
            ID = String.valueOf(((MLocator) element).getM_Locator_ID());
        else
            log.log(Level.SEVERE, "Element not NamePair - " + element.getClass().toString());
        if (key == null || ID == null) {
            if (key == null && ID == null) {
                setSelectedIndex(i);
                return;
            }
        } else if (ID.equals(key.toString())) {
            setSelectedIndex(i);
            return;
        }
    }
    setSelectedIndex(-1);
    setSelectedItem(null);
}
Also used : MLocator(org.compiere.model.MLocator) KeyNamePair(org.compiere.util.KeyNamePair) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) ComboBoxModel(javax.swing.ComboBoxModel)

Example 32 with MLocator

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

the class VLocatorDialog method actionOK.

//	createValue
/**
	 * 	OK - check for changes (save them) & Exit
	 */
private void actionOK() {
    if (fCreateNew.isSelected()) {
        //	Get Warehouse Info
        KeyNamePair pp = (KeyNamePair) fWarehouse.getSelectedItem();
        if (pp != null)
            getWarehouseInfo(pp.getKey());
        //	Check mandatory values
        String mandatoryFields = "";
        if (m_M_Warehouse_ID == 0)
            mandatoryFields += lWarehouse.getText() + " - ";
        if (fValue.getText().length() == 0)
            mandatoryFields += lValue.getText() + " - ";
        if (fX.getText().length() == 0)
            mandatoryFields += lX.getText() + " - ";
        if (fY.getText().length() == 0)
            mandatoryFields += lY.getText() + " - ";
        if (fZ.getText().length() == 0)
            mandatoryFields += lZ.getText() + " - ";
        if (mandatoryFields.length() != 0) {
            ADialog.error(m_WindowNo, this, "FillMandatory", mandatoryFields.substring(0, mandatoryFields.length() - 3));
            return;
        }
        MLocator loc = MLocator.get(Env.getCtx(), m_M_Warehouse_ID, fValue.getText(), fX.getText(), fY.getText(), fZ.getText());
        m_M_Locator_ID = loc.getM_Locator_ID();
        fLocator.addItem(loc);
        fLocator.setSelectedItem(loc);
    }
    //	createNew
    //
    log.config("M_Locator_ID=" + m_M_Locator_ID);
}
Also used : MLocator(org.compiere.model.MLocator) KeyNamePair(org.compiere.util.KeyNamePair)

Example 33 with MLocator

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

the class InventoryTestException method assertStorage.

private void assertStorage(MMDocument doc, String trxName) {
    MLocator locator = InventoryUtil.getCreateLocator(-1, doc.LocatorValue, doc.LocatorValue);
    MProduct product = InventoryUtil.getCreateProduct(doc);
    int M_ASI_ID = -1;
    if (!Util.isEmpty(doc.ASI, true)) {
        M_ASI_ID = doc.scenario.getM_ASI_ID(doc.ASI);
    }
    ArrayList<Object> params = new ArrayList<Object>();
    String sql = "SELECT" + " COALESCE(SUM(QtyOnHand),0)" + ",COALESCE(SUM(QtyReserved),0)" + ",COALESCE(SUM(QtyOrdered),0)" + " FROM M_Storage" + " WHERE M_Locator_ID=? AND M_Product_ID=?";
    params.add(locator.get_ID());
    params.add(product.get_ID());
    if (M_ASI_ID >= 0) {
        sql += " AND " + MStorage.COLUMNNAME_M_AttributeSetInstance_ID + "=?";
        params.add(M_ASI_ID);
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    BigDecimal qtyOnHand = Env.ZERO;
    BigDecimal qtyOrdered = Env.ZERO;
    BigDecimal qtyReserved = Env.ZERO;
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        DB.setParameters(pstmt, params);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            qtyOnHand = rs.getBigDecimal(1);
            qtyReserved = rs.getBigDecimal(2);
            qtyOrdered = rs.getBigDecimal(3);
        }
    } catch (SQLException e) {
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    //
    assertEquals("QtyOnHand not match " + doc, doc.Qty, qtyOnHand);
    assertEquals("QtyReserved not match " + doc, doc.QtyReserved, qtyReserved);
    assertEquals("QtyOrdered not match " + doc, doc.QtyOrdered, qtyOrdered);
}
Also used : DBException(org.adempiere.exceptions.DBException) MProduct(org.compiere.model.MProduct) SQLException(java.sql.SQLException) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal)

Example 34 with MLocator

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

the class InventoryUtil method createMovement.

public static MMovement createMovement(MMDocument doc, String trxName) {
    Properties ctx = Env.getCtx();
    int AD_Org_ID = getFirst_Org_ID();
    MProduct product = getCreateProduct(doc);
    MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
    MLocator locatorTo = getCreateLocator(AD_Org_ID, doc.LocatorValueTo, doc.LocatorValueTo);
    //
    MMovement m = new MMovement(ctx, 0, trxName);
    m.setAD_Org_ID(AD_Org_ID);
    m.setMovementDate(doc.Date);
    m.saveEx();
    //
    MMovementLine line = new MMovementLine(m);
    line.setM_Product_ID(product.get_ID());
    line.setM_Locator_ID(locator.get_ID());
    line.setM_LocatorTo_ID(locatorTo.get_ID());
    line.setMovementQty(doc.Qty);
    line.saveEx();
    //
    doc.document = m;
    processDocument(doc, MMovement.DOCACTION_Complete, MMovement.DOCSTATUS_Completed);
    checkLineCosts(doc, line, false);
    return m;
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) Properties(java.util.Properties) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 35 with MLocator

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

the class InventoryUtil method getCreateLocator.

/**
	 * Helper Method : Create Locator
	 */
public static MLocator getCreateLocator(int AD_Org_ID, String whValue, String value) {
    if (AD_Org_ID <= 0)
        AD_Org_ID = getFirst_Org_ID();
    MWarehouse wh = getCreateWarehouse(AD_Org_ID, whValue);
    MLocator locator = null;
    for (MLocator loc : wh.getLocators(false)) {
        if (loc.getValue().equals(value)) {
            locator = loc;
            break;
        }
    }
    if (locator == null) {
        locator = new MLocator(wh, value);
        locator.setXYZ(value, value, value);
    }
    if (wh.getLocators(false).length == 0) {
        locator.setIsDefault(true);
    }
    locator.saveEx();
    //
    return locator;
}
Also used : MLocator(org.compiere.model.MLocator) MWarehouse(org.compiere.model.MWarehouse)

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