Search in sources :

Example 1 with MInventoryLineMA

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

the class InventoryCountCreate method createInventoryLine.

//	doIt
/**
	 * 	Create/Add to Inventory Line
	 *	@param M_Product_ID product
	 *	@param M_Locator_ID locator
	 *	@param M_AttributeSetInstance_ID asi
	 *	@param QtyOnHand qty
	 *	@param M_AttributeSet_ID as
	 *	@return lines added
	 */
private int createInventoryLine(int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, BigDecimal QtyOnHand, int M_AttributeSet_ID) {
    boolean oneLinePerASI = false;
    if (M_AttributeSet_ID != 0) {
        MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
        oneLinePerASI = mas.isInstanceAttribute();
    }
    if (oneLinePerASI) {
        MInventoryLine line = new MInventoryLine(m_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, QtyOnHand, //	book/count
        QtyOnHand);
        if (line.save())
            return 1;
        return 0;
    }
    if (QtyOnHand.signum() == 0)
        M_AttributeSetInstance_ID = 0;
    if (m_line != null && m_line.getM_Locator_ID() == M_Locator_ID && m_line.getM_Product_ID() == M_Product_ID) {
        if (QtyOnHand.signum() == 0)
            return 0;
        //	Same ASI (usually 0)
        if (m_line.getM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID) {
            m_line.setQtyBook(m_line.getQtyBook().add(QtyOnHand));
            m_line.setQtyCount(m_line.getQtyCount().add(QtyOnHand));
            m_line.saveEx();
            return 0;
        } else //	Save Old Line info
        if (m_line.getM_AttributeSetInstance_ID() != 0) {
            MInventoryLineMA ma = new MInventoryLineMA(m_line, m_line.getM_AttributeSetInstance_ID(), m_line.getQtyBook());
            if (!ma.save())
                ;
        }
        m_line.setM_AttributeSetInstance_ID(0);
        m_line.setQtyBook(m_line.getQtyBook().add(QtyOnHand));
        m_line.setQtyCount(m_line.getQtyCount().add(QtyOnHand));
        m_line.saveEx();
        //
        MInventoryLineMA ma = new MInventoryLineMA(m_line, M_AttributeSetInstance_ID, QtyOnHand);
        if (!ma.save())
            ;
        return 0;
    }
    //	new line
    m_line = new MInventoryLine(m_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, QtyOnHand, //	book/count
    QtyOnHand);
    if (m_line.save())
        return 1;
    return 0;
}
Also used : MInventoryLineMA(org.compiere.model.MInventoryLineMA) MInventoryLine(org.compiere.model.MInventoryLine) MAttributeSet(org.compiere.model.MAttributeSet)

Example 2 with MInventoryLineMA

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

the class InventoryCountUpdate method updateWithMA.

//	doIt
/**
	 * 	Update Inventory Lines With Material Allocation
	 *	@return no updated
	 */
private int updateWithMA() {
    int no = 0;
    //
    String sql = "SELECT * FROM M_InventoryLine WHERE M_Inventory_ID=? AND M_AttributeSetInstance_ID=0";
    PreparedStatement preparedStatement = null;
    try {
        preparedStatement = DB.prepareStatement(sql, get_TrxName());
        preparedStatement.setInt(1, getRecord_ID());
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            MInventoryLine inventoryLine = new MInventoryLine(getCtx(), resultSet, get_TrxName());
            BigDecimal onHand = Env.ZERO;
            MStorage[] storages = MStorage.getAll(getCtx(), inventoryLine.getM_Product_ID(), inventoryLine.getM_Locator_ID(), get_TrxName());
            MInventoryLineMA inventoryLineMA = null;
            for (int i = 0; i < storages.length; i++) {
                MStorage storage = storages[i];
                if (storage.getQtyOnHand().signum() == 0)
                    continue;
                onHand = onHand.add(storage.getQtyOnHand());
                //	No ASI
                if (storage.getM_AttributeSetInstance_ID() == 0 && storages.length == 1)
                    continue;
                //	Save ASI
                inventoryLineMA = new MInventoryLineMA(inventoryLine, storage.getM_AttributeSetInstance_ID(), storage.getQtyOnHand());
                if (!inventoryLineMA.save())
                    ;
            }
            inventoryLine.setQtyBook(onHand);
            if (isUpdateCountQty())
                inventoryLine.setQtyCount(onHand);
            if (inventoryLine.save())
                no++;
        }
        resultSet.close();
        preparedStatement.close();
        preparedStatement = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    }
    try {
        if (preparedStatement != null)
            preparedStatement.close();
        preparedStatement = null;
    } catch (Exception e) {
        preparedStatement = null;
    }
    //
    log.info("#" + no);
    return no;
}
Also used : MInventoryLineMA(org.compiere.model.MInventoryLineMA) MInventoryLine(org.compiere.model.MInventoryLine) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal)

Aggregations

MInventoryLine (org.compiere.model.MInventoryLine)2 MInventoryLineMA (org.compiere.model.MInventoryLineMA)2 BigDecimal (java.math.BigDecimal)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 MAttributeSet (org.compiere.model.MAttributeSet)1 MStorage (org.compiere.model.MStorage)1