Search in sources :

Example 26 with MLocator

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

the class WLocatorDialog method actionOK.

// createValue
/**
	 * 	OK - check for changes (save them) & Exit
	 */
private void actionOK() {
    if (chkCreateNew.isChecked()) {
        //	Get Warehouse Info
        ListItem listitem = lstWarehouse.getSelectedItem();
        KeyNamePair pp = (KeyNamePair) listitem.getValue();
        if (pp != null)
            getWarehouseInfo(pp.getKey());
        //	Check mandatory values
        String mandatoryFields = "";
        if (m_M_Warehouse_ID == 0)
            mandatoryFields += lblWarehouse.getValue() + " - ";
        if (txtKey.getText().length() == 0)
            mandatoryFields += lblKey.getValue() + " - ";
        if (txtAisleX.getText().length() == 0)
            mandatoryFields += lblAisleX.getValue() + " - ";
        if (txtBinY.getText().length() == 0)
            mandatoryFields += lblBinY.getValue() + " - ";
        if (txtLevelZ.getText().length() == 0)
            mandatoryFields += lblLevelZ.getValue() + " - ";
        if (mandatoryFields.length() != 0) {
            FDialog.error(m_WindowNo, this, "FillMandatory", mandatoryFields.substring(0, mandatoryFields.length() - 3));
            return;
        }
        MLocator loc = MLocator.get(Env.getCtx(), m_M_Warehouse_ID, txtKey.getText(), txtAisleX.getText(), txtBinY.getText(), txtLevelZ.getText());
        m_M_Locator_ID = loc.getM_Locator_ID();
        listitem = new ListItem();
        listitem.setValue(loc);
        lstLocator.appendItem(loc.get_TableName(), loc);
        lstLocator.setSelectedIndex(lstLocator.getItemCount() - 1);
    }
    // createNew
    log.config("M_Locator_ID=" + m_M_Locator_ID);
}
Also used : MLocator(org.compiere.model.MLocator) ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair)

Example 27 with MLocator

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

the class MovementGenerate method createLine.

//	generate
/**************************************************************************
	 * 	Create Line
	 *	@param Distribution order order
	 *	@param orderLine line
	 *	@param qty qty
	 *	@param storages storage info
	 *	@param force force delivery
	 */
private void createLine(MDDOrder order, MDDOrderLine orderLine, BigDecimal qty, MStorage[] storages, boolean force) {
    //	Complete last Shipment - can have multiple shipments
    if (m_lastC_BPartner_Location_ID != order.getC_BPartner_Location_ID())
        completeMovement();
    m_lastC_BPartner_Location_ID = order.getC_BPartner_Location_ID();
    //	Create New Shipment
    if (m_movement == null) {
        MLocator locator = MLocator.get(getCtx(), orderLine.getM_Locator_ID());
        m_movement = createMovement(order, m_movementDate);
        m_movement.setAD_Org_ID(locator.getAD_Org_ID());
        //m_movement.setM_Warehouse_ID(orderLine.getM_Warehouse_ID());	//	sets Org too
        m_movement.setIsInTransit(true);
        m_movement.setDD_Order_ID(order.getDD_Order_ID());
        if (order.getC_BPartner_ID() != order.getC_BPartner_ID())
            m_movement.setC_BPartner_ID(order.getC_BPartner_ID());
        if (order.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID())
            m_movement.setC_BPartner_Location_ID(order.getC_BPartner_Location_ID());
        //Look the document type based on organization
        int docTypeDO_ID = getDocType(MDocType.DOCBASETYPE_MaterialMovement, m_movement.getAD_Org_ID());
        if (docTypeDO_ID > 0)
            m_movement.setC_DocType_ID(docTypeDO_ID);
        if (!m_movement.save())
            throw new IllegalStateException("Could not create Movement");
    }
    //	Non Inventory Lines
    if (storages == null) {
        MMovementLine line = new MMovementLine(m_movement);
        line.setOrderLine(orderLine, Env.ZERO, false);
        //	Correct UOM
        line.setMovementQty(qty);
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setMovementQty(qty.multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine(line.toString());
        return;
    }
    //	Product
    MProduct product = orderLine.getProduct();
    boolean linePerASI = false;
    if (product.getM_AttributeSet_ID() != 0) {
        MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
        linePerASI = mas.isInstanceAttribute();
    }
    //	Inventory Lines
    ArrayList<MMovementLine> list = new ArrayList<MMovementLine>();
    BigDecimal toDeliver = qty;
    for (int i = 0; i < storages.length; i++) {
        MStorage storage = storages[i];
        BigDecimal deliver = toDeliver;
        //	Not enough On Hand
        if (deliver.compareTo(storage.getQtyOnHand()) > 0 && //	positive storage
        storage.getQtyOnHand().signum() >= 0) {
            if (//	Adjust to OnHand Qty  
            !force || //	if force not on last location
            (force && i + 1 != storages.length))
                deliver = storage.getQtyOnHand();
        }
        if (//	zero deliver
        deliver.signum() == 0)
            continue;
        int M_Locator_ID = storage.getM_Locator_ID();
        //
        MMovementLine line = null;
        if (//	find line with Locator
        !linePerASI) {
            for (int ll = 0; ll < list.size(); ll++) {
                MMovementLine test = (MMovementLine) list.get(ll);
                if (test.getM_Locator_ID() == M_Locator_ID) {
                    line = test;
                    break;
                }
            }
        }
        if (//	new line
        line == null) {
            line = new MMovementLine(m_movement);
            line.setOrderLine(orderLine, deliver, false);
            line.setMovementQty(deliver);
            list.add(line);
        } else
            //	existing line
            line.setMovementQty(line.getMovementQty().add(deliver));
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setMovementQty(line.getMovementQty().multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (linePerASI)
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
        toDeliver = toDeliver.subtract(deliver);
        //	Temp adjustment
        storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver));
        //
        if (toDeliver.signum() == 0)
            break;
    }
    if (toDeliver.signum() != 0)
        throw new IllegalStateException("Not All Delivered - Remainder=" + toDeliver);
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) MMovementLine(org.compiere.model.MMovementLine) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet)

Example 28 with MLocator

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

the class MDDOrderLine method beforeSave.

//	setQtyOrdered
/**************************************************************************
	 * 	Before Save
	 *	@param newRecord
	 *	@return true if it can be sabed
	 */
protected boolean beforeSave(boolean newRecord) {
    if (newRecord && getParent().isComplete()) {
        log.saveError("ParentComplete", Msg.translate(getCtx(), "DD_OrderLine"));
        return false;
    }
    /*if (getC_BPartner_ID() == 0 || getC_BPartner_Location_ID() == 0
			|| getM_Warehouse_ID() == 0)
			setOrder (getParent());*/
    if (m_M_PriceList_ID == 0)
        setHeaderInfo(getParent());
    //	R/O Check - Product/Warehouse Change
    if (!newRecord && (is_ValueChanged("M_Product_ID") || is_ValueChanged("M_Locator_ID") || is_ValueChanged("M_LocatorTo_ID"))) {
        if (!canChangeWarehouse())
            return false;
    }
    //	Charge
    if (getC_Charge_ID() != 0 && getM_Product_ID() != 0)
        setM_Product_ID(0);
    //	No Product
    if (getM_Product_ID() == 0)
        setM_AttributeSetInstance_ID(0);
    //	UOM
    if (getC_UOM_ID() == 0 && (getM_Product_ID() != 0 || getC_Charge_ID() != 0)) {
        int C_UOM_ID = MUOM.getDefault_UOM_ID(getCtx());
        if (C_UOM_ID > 0)
            setC_UOM_ID(C_UOM_ID);
    }
    //	Qty Precision
    if (newRecord || is_ValueChanged("QtyEntered"))
        setQtyEntered(getQtyEntered());
    if (newRecord || is_ValueChanged("QtyOrdered"))
        setQtyOrdered(getQtyOrdered());
    //	Qty on instance ASI for SO
    if (m_IsSOTrx && getM_AttributeSetInstance_ID() != 0 && (newRecord || is_ValueChanged("M_Product_ID") || is_ValueChanged("M_AttributeSetInstance_ID") || is_ValueChanged("M_Warehouse_ID"))) {
        MProduct product = getProduct();
        if (product.isStocked()) {
            int M_AttributeSet_ID = product.getM_AttributeSet_ID();
            boolean isInstance = M_AttributeSet_ID != 0;
            if (isInstance) {
                MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
                isInstance = mas.isInstanceAttribute();
            }
            //	Max
            if (isInstance) {
                MLocator locator_from = MLocator.get(getCtx(), getM_Locator_ID());
                MStorage[] storages = MStorage.getWarehouse(getCtx(), locator_from.getM_Warehouse_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), M_AttributeSet_ID, false, null, true, get_TrxName());
                BigDecimal qty = Env.ZERO;
                for (int i = 0; i < storages.length; i++) {
                    if (storages[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID())
                        qty = qty.add(storages[i].getQtyOnHand());
                }
                if (getQtyOrdered().compareTo(qty) > 0) {
                    log.warning("Qty - Stock=" + qty + ", Ordered=" + getQtyOrdered());
                    log.saveError("QtyInsufficient", "=" + qty);
                    return false;
                }
            }
        }
    //	stocked
    }
    //	FreightAmt Not used
    if (Env.ZERO.compareTo(getFreightAmt()) != 0)
        setFreightAmt(Env.ZERO);
    //	Get Line No
    if (getLine() == 0) {
        String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM DD_OrderLine WHERE DD_Order_ID=?";
        int ii = DB.getSQLValue(get_TrxName(), sql, getDD_Order_ID());
        setLine(ii);
    }
    return true;
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet)

Example 29 with MLocator

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

the class MPPOrder method createMethodChangeVariance.

private void createMethodChangeVariance(MPPOrderBOMLine line) {
    MPPOrder order = this;
    Timestamp movementDate = order.getUpdated();
    // (a product that "was not" in BOM was used)
    if (line.getQtyBatch().signum() != 0 && line.getQtyBOM().signum() != 0)
        return;
    // Previous booked method Change  variance
    final BigDecimal qtyMethodChangeVariancePrev = line.getQtyMethodChangeVariance();
    final BigDecimal qtyOpen = line.getQtyOpen();
    // Current usage variance = QtyOpen - Previous Method Change Variance 
    final BigDecimal qtyMethodChangeVariance = qtyOpen.subtract(qtyMethodChangeVariancePrev);
    //
    if (qtyMethodChangeVariance.signum() == 0)
        return;
    // Get Locator
    int M_Locator_ID = line.getM_Locator_ID();
    if (M_Locator_ID <= 0) {
        MLocator locator = MLocator.getDefault(MWarehouse.get(order.getCtx(), order.getM_Warehouse_ID()));
        if (locator != null)
            M_Locator_ID = locator.getM_Locator_ID();
    }
    //
    MPPCostCollector cc = MPPCostCollector.createCollector(order, line.getM_Product_ID(), M_Locator_ID, line.getM_AttributeSetInstance_ID(), order.getS_Resource_ID(), line.getPP_Order_BOMLine_ID(), //PP_Order_Node_ID,
    0, // C_DocType_ID,
    MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingCostCollector), MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance, movementDate, // Qty
    qtyMethodChangeVariance, // scrap,
    Env.ZERO, // reject,
    Env.ZERO, //durationSetup,
    Env.ZERO, // duration
    Env.ZERO);
}
Also used : MLocator(org.compiere.model.MLocator) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 30 with MLocator

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

the class MPPOrder method createUsageVariance.

private void createUsageVariance(I_PP_Order_BOMLine bomLine) {
    MPPOrder order = this;
    Timestamp movementDate = order.getUpdated();
    MPPOrderBOMLine line = (MPPOrderBOMLine) bomLine;
    // (a product that "was not" in BOM was used)
    if (line.getQtyBatch().signum() == 0 && line.getQtyBOM().signum() == 0) {
        return;
    }
    // Previous booked usage variance
    final BigDecimal qtyUsageVariancePrev = line.getQtyVariance();
    final BigDecimal qtyOpen = line.getQtyOpen();
    // Current usage variance = QtyOpen - Previous Usage Variance 
    final BigDecimal qtyUsageVariance = qtyOpen.subtract(qtyUsageVariancePrev);
    //
    if (qtyUsageVariance.signum() == 0)
        return;
    // Get Locator
    int M_Locator_ID = line.getM_Locator_ID();
    if (M_Locator_ID <= 0) {
        MLocator locator = MLocator.getDefault(MWarehouse.get(order.getCtx(), order.getM_Warehouse_ID()));
        if (locator != null)
            M_Locator_ID = locator.getM_Locator_ID();
    }
    //
    MPPCostCollector.createCollector(order, line.getM_Product_ID(), M_Locator_ID, line.getM_AttributeSetInstance_ID(), order.getS_Resource_ID(), line.getPP_Order_BOMLine_ID(), //PP_Order_Node_ID,
    0, // C_DocType_ID,
    MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingCostCollector), MPPCostCollector.COSTCOLLECTORTYPE_UsegeVariance, movementDate, // Qty
    qtyUsageVariance, // scrap,
    Env.ZERO, // reject,
    Env.ZERO, //durationSetup,
    Env.ZERO, // duration
    Env.ZERO);
}
Also used : MLocator(org.compiere.model.MLocator) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

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