Search in sources :

Example 1 with MProductCategory

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

the class MovementGenerate method generate.

//	doIt
/**
	 * 	Generate Shipments
	 * 	@param pstmt Order Query
	 *	@return info
	 */
private String generate(PreparedStatement pstmt) {
    MClient client = MClient.get(getCtx());
    try {
        ResultSet rs = pstmt.executeQuery();
        while (//	Order
        rs.next()) {
            MDDOrder order = new MDDOrder(getCtx(), rs, get_TrxName());
            //	New Header different Shipper, Shipment Location
            if (!p_ConsolidateDocument || (m_movement != null && (m_movement.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || m_movement.getM_Shipper_ID() != order.getM_Shipper_ID()))) {
                completeMovement();
            }
            log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
            //
            Timestamp minGuaranteeDate = m_movementDate;
            boolean completeOrder = MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
            //	OrderLine WHERE
            String where = " " + p_M_Warehouse_ID + " IN (SELECT l.M_Warehouse_ID FROM M_Locator l WHERE l.M_Locator_ID=M_Locator_ID) ";
            if (p_DatePromised != null)
                where += " AND (TRUNC(DatePromised)<=" + DB.TO_DATE(p_DatePromised, true) + " OR DatePromised IS NULL)";
            //	Exclude Auto Delivery if not Force
            if (!MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
                where += " AND (DD_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE DD_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))";
            //	Exclude Unconfirmed
            if (!p_IsUnconfirmedInOut)
                where += " AND NOT EXISTS (SELECT * FROM M_MovementLine iol" + " INNER JOIN M_Movement io ON (iol.M_Movement_ID=io.M_Movement_ID) " + "WHERE iol.DD_OrderLine_ID=DD_OrderLine.DD_OrderLine_ID AND io.DocStatus IN ('IP','WC'))";
            //	Deadlock Prevention - Order by M_Product_ID
            MDDOrderLine[] lines = order.getLines(where, "M_Product_ID");
            for (int i = 0; i < lines.length; i++) {
                MDDOrderLine line = lines[i];
                MLocator l = new MLocator(getCtx(), line.getM_Locator_ID(), get_TrxName());
                if (l.getM_Warehouse_ID() != p_M_Warehouse_ID)
                    continue;
                log.fine("check: " + line);
                BigDecimal onHand = Env.ZERO;
                //BigDecimal toDeliver = line.getQtyOrdered()
                //.subtract(line.getQtyDelivered());
                BigDecimal toDeliver = line.getConfirmedQty();
                MProduct product = line.getProduct();
                //	Nothing to Deliver
                if (product != null && toDeliver.signum() == 0)
                    continue;
                // or it's a charge - Bug#: 1603966 
                if (line.getC_Charge_ID() != 0 && toDeliver.signum() == 0)
                    continue;
                //	Check / adjust for confirmations
                BigDecimal unconfirmedShippedQty = Env.ZERO;
                if (p_IsUnconfirmedInOut && product != null && toDeliver.signum() != 0) {
                    String where2 = "EXISTS (SELECT * FROM M_Movement io WHERE io.M_Movement_ID=M_MovementLine.M_Movement_ID AND io.DocStatus IN ('IP','WC'))";
                    MMovementLine[] iols = MMovementLine.getOfOrderLine(getCtx(), line.getDD_OrderLine_ID(), where2, null);
                    for (int j = 0; j < iols.length; j++) unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty());
                    String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + toDeliver + "->";
                    toDeliver = toDeliver.subtract(unconfirmedShippedQty);
                    logInfo += toDeliver;
                    if (toDeliver.signum() < 0) {
                        toDeliver = Env.ZERO;
                        logInfo += " (set to 0)";
                    }
                    //	Adjust On Hand
                    onHand = onHand.subtract(unconfirmedShippedQty);
                    log.fine(logInfo);
                }
                //	Comments & lines w/o product & services
                if ((product == null || !product.isStocked()) && (//	comments
                line.getQtyOrdered().signum() == 0 || //	lines w/o product
                toDeliver.signum() != 0)) {
                    if (//	printed later
                    !MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
                        createLine(order, line, toDeliver, null, false);
                    continue;
                }
                //	Stored Product
                MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID());
                String MMPolicy = pc.getMMPolicy();
                if (MMPolicy == null || MMPolicy.length() == 0)
                    MMPolicy = client.getMMPolicy();
                //
                MStorage[] storages = getStorages(l.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), line.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
                for (int j = 0; j < storages.length; j++) {
                    MStorage storage = storages[j];
                    onHand = onHand.add(storage.getQtyOnHand());
                }
                boolean fullLine = onHand.compareTo(toDeliver) >= 0 || toDeliver.signum() < 0;
                //	Complete Order
                if (completeOrder && !fullLine) {
                    log.fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
                    completeOrder = false;
                    break;
                } else //	Complete Line
                if (fullLine && MDDOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
                    log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + line);
                    //	
                    createLine(order, line, toDeliver, storages, false);
                } else //	Availability
                if (MDDOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) && (onHand.signum() > 0 || toDeliver.signum() < 0)) {
                    BigDecimal deliver = toDeliver;
                    if (deliver.compareTo(onHand) > 0)
                        deliver = onHand;
                    log.fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
                    //	
                    createLine(order, line, deliver, storages, false);
                } else //	Force
                if (MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
                    BigDecimal deliver = toDeliver;
                    log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
                    //	
                    createLine(order, line, deliver, storages, true);
                } else //	Manual
                if (MDDOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
                    log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + line);
                else
                    log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
            }
            //	Complete Order successful
            if (completeOrder && MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
                for (int i = 0; i < lines.length; i++) {
                    MDDOrderLine line = lines[i];
                    MLocator l = new MLocator(getCtx(), line.getM_Locator_ID(), get_TrxName());
                    if (l.getM_Warehouse_ID() != p_M_Warehouse_ID)
                        continue;
                    MProduct product = line.getProduct();
                    BigDecimal toDeliver = line.getQtyOrdered().subtract(line.getQtyDelivered());
                    //
                    MStorage[] storages = null;
                    if (product != null && product.isStocked()) {
                        MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID());
                        String MMPolicy = pc.getMMPolicy();
                        if (MMPolicy == null || MMPolicy.length() == 0)
                            MMPolicy = client.getMMPolicy();
                        //
                        storages = getStorages(l.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), line.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
                    }
                    //	
                    createLine(order, line, toDeliver, storages, false);
                }
            }
            m_line += 1000;
        }
        //	while order
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, m_sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    completeMovement();
    return "@Created@ = " + m_created;
}
Also used : MProduct(org.compiere.model.MProduct) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) MClient(org.compiere.model.MClient) MDDOrderLine(org.eevolution.model.MDDOrderLine) MProductCategory(org.compiere.model.MProductCategory) MLocator(org.compiere.model.MLocator) ResultSet(java.sql.ResultSet) MDDOrder(org.eevolution.model.MDDOrder) MMovementLine(org.compiere.model.MMovementLine)

Example 2 with MProductCategory

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

the class InventoryUtil method getCreateProductCategory.

public static MProductCategory getCreateProductCategory(String value, String MMPolicy) {
    if (MMPolicy == null)
        MMPolicy = MProductCategory.MMPOLICY_FiFo;
    Properties ctx = Env.getCtx();
    final String whereClause = I_M_Product_Category.COLUMNNAME_Value + "=?";
    MProductCategory pc = new Query(ctx, I_M_Product_Category.Table_Name, whereClause, null).setParameters(value).setOnlyActiveRecords(true).setClient_ID().firstOnly();
    if (pc == null) {
        pc = new MProductCategory(ctx, 0, null);
    }
    pc.setValue(value);
    pc.setName(value);
    setGeneratedTag(pc);
    pc.setMMPolicy(MMPolicy);
    //
    pc.saveEx();
    return pc;
}
Also used : Query(org.compiere.model.Query) MProductCategory(org.compiere.model.MProductCategory) Properties(java.util.Properties)

Example 3 with MProductCategory

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

the class InventoryUtil method getCreateProductCategory.

public static MProductCategory getCreateProductCategory(String value, String MMPolicy, String CostingLevel, String CostingMethod) {
    if (Util.isEmpty(value, true))
        throw new IllegalArgumentException("Value is null");
    if (MMPolicy == null)
        MMPolicy = MProductCategory.MMPOLICY_FiFo;
    Properties ctx = Env.getCtx();
    String whereClause = MProductCategory.COLUMNNAME_Value + "=?";
    MProductCategory pc = new Query(ctx, MProductCategory.Table_Name, whereClause, null).setParameters(new Object[] { value }).setOnlyActiveRecords(true).setClient_ID().firstOnly();
    if (pc == null) {
        pc = new MProductCategory(ctx, 0, null);
    }
    pc.setValue(value);
    pc.setName(value);
    setGeneratedTag(pc);
    pc.setMMPolicy(MMPolicy);
    //
    pc.saveEx();
    //
    int C_AcctSchema_ID = MClientInfo.get(ctx).getC_AcctSchema1_ID();
    MProductCategoryAcct pca = MProductCategoryAcct.get(ctx, pc.get_ID(), C_AcctSchema_ID, null);
    pca.setCostingLevel(CostingLevel);
    pca.setCostingMethod(CostingMethod);
    pca.saveEx();
    //
    return pc;
}
Also used : Query(org.compiere.model.Query) MProductCategory(org.compiere.model.MProductCategory) MProductCategoryAcct(org.compiere.model.MProductCategoryAcct) Properties(java.util.Properties)

Example 4 with MProductCategory

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

the class InventoryUtil method getCreateProduct.

public static MProduct getCreateProduct(String value, String MMPolicy, String CostingLevel, String CostingMethod) {
    Properties ctx = Env.getCtx();
    //
    MProductCategory pc = getCreateProductCategory(value, MMPolicy, CostingLevel, CostingMethod);
    //
    MProduct product = new Query(ctx, MProduct.Table_Name, "Value=?", null).setParameters(new Object[] { value }).setOnlyActiveRecords(true).setClient_ID().firstOnly();
    if (product == null) {
        product = new MProduct(ctx, 0, null);
    }
    product.setValue(value);
    product.setName(value);
    setGeneratedTag(product);
    product.setProductType(MProduct.PRODUCTTYPE_Item);
    product.setIsStocked(true);
    // Each
    product.setC_UOM_ID(100);
    product.setC_TaxCategory_ID(getDefault_TaxCategory_ID());
    product.setM_Product_Category_ID(pc.get_ID());
    product.saveEx();
    //
    getCreateProductPrice("#PO_PriceList_ID", product.get_ID(), 10);
    getCreateProductPrice("#SO_PriceList_ID", product.get_ID(), 20);
    //
    return product;
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MProductCategory(org.compiere.model.MProductCategory) Properties(java.util.Properties)

Example 5 with MProductCategory

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

the class ProjectCreateAsset method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (translated text)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    if (m_C_Project_ID == 0) {
        return "Missing Mandatory Field Value (Project)";
    }
    MProject project = new MProject(getCtx(), m_C_Project_ID, get_TrxName());
    log.info("doIt - " + project);
    // Goodwill
    if (!MProject.PROJECTCATEGORY_AssetProject.equals(project.getProjectCategory()))
        return "Project is not asset type";
    //
    MProduct product = new MProduct(getCtx(), m_Product_ID, get_TrxName());
    MProductCategory pc = MProductCategory.get(getCtx(), product.getM_Product_Category_ID());
    if (pc.getA_Asset_Group_ID() == 0) {
        return "Product is not asset type";
    }
    MAssetAddition assetAdd = MAssetAddition.createAsset(project, product);
    assetAdd.setDateAcct(m_DateTrx);
    assetAdd.setDateDoc(m_DateTrx);
    assetAdd.setM_Product_ID(m_Product_ID);
    if (m_UseLifeYears > 0) {
        assetAdd.setDeltaUseLifeYears(m_UseLifeYears);
        assetAdd.setDeltaUseLifeYears_F(m_UseLifeYears);
    }
    assetAdd.saveEx();
    if (!assetAdd.processIt(DocAction.ACTION_Complete)) {
        return "Error Process Asset Addition";
    }
    assetAdd.saveEx();
    message += ". @A_Asset_Addition_ID@ - " + assetAdd;
    return "Asset Created " + message;
}
Also used : MProduct(org.compiere.model.MProduct) MAssetAddition(org.compiere.model.MAssetAddition) MProductCategory(org.compiere.model.MProductCategory) MProject(org.compiere.model.MProject)

Aggregations

MProductCategory (org.compiere.model.MProductCategory)7 MProduct (org.compiere.model.MProduct)4 Query (org.compiere.model.Query)4 Properties (java.util.Properties)3 BigDecimal (java.math.BigDecimal)2 Timestamp (java.sql.Timestamp)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MClient (org.compiere.model.MClient)2 MLocator (org.compiere.model.MLocator)2 MMovementLine (org.compiere.model.MMovementLine)2 MStorage (org.compiere.model.MStorage)2 MDDOrder (org.eevolution.model.MDDOrder)2 MDDOrderLine (org.eevolution.model.MDDOrderLine)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 MAssetAddition (org.compiere.model.MAssetAddition)1