Search in sources :

Example 41 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MPPOrder method updateMakeToKit.

/**
	 * Create Auto Receipt and Issue based on Quantity
	 * @param qtyShipment
	 */
public void updateMakeToKit(BigDecimal qtyShipment) {
    MPPOrderBOM orderBOM = (MPPOrderBOM) getMPPOrderBOM();
    getLines(true);
    // Auto receipt and issue for kit
    if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(orderBOM.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(orderBOM.getBOMUse())) {
        Timestamp today = new Timestamp(System.currentTimeMillis());
        ArrayList[][] issue = new ArrayList[m_lines.length][1];
        for (int i = 0; i < getLines().length; i++) {
            MPPOrderBOMLine line = m_lines[i];
            KeyNamePair id = null;
            if (MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) {
                id = new KeyNamePair(line.get_ID(), "Y");
            } else
                id = new KeyNamePair(line.get_ID(), "N");
            ArrayList<Object> data = new ArrayList<Object>();
            BigDecimal qtyToDeliver = qtyShipment.multiply(line.getQtyMultiplier());
            //0 - MPPOrderBOMLine ID
            data.add(id);
            //1 - Critical
            data.add(line.isCritical());
            MProduct product = (MProduct) line.getM_Product();
            //2 - Value
            data.add(product.getValue());
            KeyNamePair productKey = new KeyNamePair(product.get_ID(), product.getName());
            //3 - KeyNamePair Product
            data.add(productKey);
            //4 - QtyToDeliver			
            data.add(qtyToDeliver);
            //5 - QtyScrapComponent
            data.add(Env.ZERO);
            issue[i][0] = data;
        }
        boolean forceIssue = false;
        MOrderLine orderLine = (MOrderLine) getC_OrderLine();
        if (MOrder.DELIVERYRULE_CompleteLine.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_CompleteOrder.equals(orderLine.getParent().getDeliveryRule())) {
            boolean isCompleteQtyDeliver = MPPOrder.isQtyAvailable(this, issue, today);
            if (!isCompleteQtyDeliver) {
                throw new AdempiereException("@NoQtyAvailable@");
            }
        } else if (MOrder.DELIVERYRULE_Availability.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_AfterReceipt.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_Manual.equals(orderLine.getParent().getDeliveryRule())) {
            throw new AdempiereException("@DeliveryRule@ " + orderLine.getParent().getDeliveryRule() + "@ActionNotSupported@");
        } else if (MOrder.DELIVERYRULE_Force.equals(orderLine.getParent().getDeliveryRule())) {
            forceIssue = true;
        }
        for (int i = 0; i < issue.length; i++) {
            int attributeSetInstanceId = 0;
            KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
            Boolean isCritical = (Boolean) issue[i][0].get(1);
            String value = (String) issue[i][0].get(2);
            KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
            int productId = productkey.getKey();
            MProduct product = MProduct.get(getCtx(), productId);
            BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
            BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
            MPPOrderBOMLine orderBOMLine = null;
            int orderBOMLineId = (Integer) key.getKey();
            if (orderBOMLineId > 0) {
                orderBOMLine = new MPPOrderBOMLine(getCtx(), orderBOMLineId, get_TrxName());
                //Validate if AttributeSet generate instance
                attributeSetInstanceId = orderBOMLine.getM_AttributeSetInstance_ID();
            }
            MStorage[] storages = MPPOrder.getStorages(getCtx(), productId, getM_Warehouse_ID(), attributeSetInstanceId, today, get_TrxName());
            MPPOrder.createIssue(this, orderBOMLine, today, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
        }
        MPPOrder.createReceipt(this, today, getQtyDelivered(), qtyShipment, getQtyScrap(), getQtyReject(), getM_Locator_ID(), getM_AttributeSetInstance_ID());
    }
}
Also used : MProduct(org.compiere.model.MProduct) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) KeyNamePair(org.compiere.util.KeyNamePair) MOrderLine(org.compiere.model.MOrderLine)

Example 42 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class CalloutBOM method parent.

/**
	 *	Parent cycle check and BOM Line defaults.
	 *  @param ctx      Context
	 *  @param WindowNo current Window No
	 *  @param mTab     Model Tab
	 *  @param mField   Model Field
	 *  @param value    The new value
	 */
public String parent(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    if (isCalloutActive() || value == null)
        return "";
    final int M_Product_ID = (Integer) value;
    if (M_Product_ID <= 0)
        return "";
    I_PP_Product_BOMLine bomLine = GridTabWrapper.create(mTab, I_PP_Product_BOMLine.class);
    I_PP_Product_BOM bom = bomLine.getPP_Product_BOM();
    if (//Adempiere-272 changes
    bom == null) {
        throw new AdempiereException("Please save header record first.");
    }
    if (bom.getM_Product_ID() == bomLine.getM_Product_ID()) {
        throw new AdempiereException("@ValidComponent@ - Error Parent not be Component");
    }
    // Set BOM Line defaults
    // May be the parent;
    MProduct product = MProduct.get(ctx, M_Product_ID);
    bomLine.setDescription(product.getDescription());
    bomLine.setHelp(product.getHelp());
    bomLine.setC_UOM_ID(product.getC_UOM_ID());
    bomLine.setM_AttributeSetInstance_ID(product.getEnvAttributeSetInstance(ctx, WindowNo) == null ? 0 : product.getEnvAttributeSetInstance(ctx, WindowNo));
    return "";
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 43 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MPPOrder method closeIt.

//	voidIt
public boolean closeIt() {
    log.info(toString());
    // Before Close
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_CLOSE);
    if (m_processMsg != null)
        return false;
    if (MPPOrder.DOCSTATUS_Closed.equals(getDocStatus()))
        return true;
    if (!MPPOrder.DOCSTATUS_Completed.equals(getDocStatus())) {
        String DocStatus = completeIt();
        setDocStatus(DocStatus);
        setDocAction(MPPOrder.ACTION_None);
    }
    if (!isDelivered()) {
        // TODO: Create Message for Translation
        throw new AdempiereException("Cannot close this document because do not exist transactions");
    }
    createVariances();
    for (MPPOrderBOMLine line : getLines()) {
        BigDecimal old = line.getQtyRequired();
        if (old.compareTo(line.getQtyDelivered()) != 0) {
            line.setQtyRequired(line.getQtyDelivered());
            line.addDescription(Msg.parseTranslation(getCtx(), "@closed@ @QtyRequired@ (" + old + ")"));
            line.saveEx();
        }
    }
    //Close all the activity do not reported
    MPPOrderWorkflow m_order_wf = getMPPOrderWorkflow();
    m_order_wf.closeActivities(m_order_wf.getLastNode(getAD_Client_ID()), getUpdated(), false);
    BigDecimal old = getQtyOrdered();
    if (old.signum() != 0) {
        addDescription(Msg.parseTranslation(getCtx(), "@closed@ @QtyOrdered@ : (" + old + ")"));
        setQtyOrdered(getQtyDelivered());
        saveEx();
    }
    // Clear Ordered Quantities
    orderStock();
    //	Clear Reservations
    reserveStock(getLines());
    setDocStatus(DOCSTATUS_Closed);
    //setProcessed(true);
    setDocAction(DOCACTION_None);
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_CLOSE);
    if (m_processMsg != null)
        return false;
    return true;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) BigDecimal(java.math.BigDecimal)

Example 44 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MPPOrderWorkflow method closeActivities.

//	getDurationCalendarField
/**
	 * Close Activities
	 * @param activity current activity / reporting activity
	 * @param movementDate
	 * @param milestone stop on previous milestone
	 */
public void closeActivities(MPPOrderNode activity, Timestamp movementDate, boolean milestone) {
    if (activity.getPP_Order_Workflow_ID() != get_ID()) {
        throw new AdempiereException("Activity and Order Workflow not matching" + " (" + activity + ", PP_Order_Workflow_ID=" + get_ID() + ")");
    }
    MPPOrder order = getMPPOrder();
    for (int nodeId = activity.get_ID(); nodeId != 0; nodeId = getPrevious(nodeId, getAD_Client_ID())) {
        MPPOrderNode node = getNode(nodeId);
        // Break the cycle 
        if (milestone && node.isMilestone() && node.get_ID() != activity.get_ID()) {
            break;
        }
        if (MPPOrderNode.DOCSTATUS_Drafted.equals(node.getDocStatus())) {
            BigDecimal qtyToDeliver = node.getQtyToDeliver();
            if (qtyToDeliver.signum() <= 0) {
                // TODO: should we create a negate CC?
                continue;
            }
            BigDecimal setupTimeReal = node.getSetupTimeRequired().subtract(node.getSetupTimeReal());
            RoutingService routingService = RoutingServiceFactory.get().getRoutingService(node.getAD_Client_ID());
            BigDecimal durationReal = routingService.estimateWorkingTime(node, qtyToDeliver);
            // arhipac: cristi_pup: Generate even if nothing was reporting on this activity
            // https://sourceforge.net/projects/adempiere/forums/forum/639403/topic/3407220
            //				if (setupTimeReal <= 0 && durationReal.signum() <= 0)
            //				{
            //					continue;
            //				}
            MPPCostCollector.createCollector(//MPPOrder
            order, //M_Product_ID
            order.getM_Product_ID(), //M_Locator_ID
            order.getM_Locator_ID(), //M_AttributeSetInstance_ID
            order.getM_AttributeSetInstance_ID(), //S_Resource_ID
            node.getS_Resource_ID(), //PP_Order_BOMLine_ID
            0, //PP_Order_Node_ID
            node.get_ID(), //C_DocType_ID,
            MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingCostCollector), //Activity Control
            MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl, //MovementDate
            movementDate, //qty,scrap,reject
            qtyToDeliver, //qty,scrap,reject
            Env.ZERO, //qty,scrap,reject
            Env.ZERO, setupTimeReal, //durationSetup,duration
            durationReal);
            // reload because it was modified outside of our context
            node.load(order.get_TrxName());
            node.closeIt();
            node.saveEx();
        } else if (MPPOrderNode.DOCSTATUS_Completed.equals(node.getDocStatus()) || MPPOrderNode.DOCSTATUS_InProgress.equals(node.getDocStatus())) {
            node.closeIt();
            node.saveEx();
        }
    }
    // for each node
    // reset nodes
    m_nodes = null;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) BigDecimal(java.math.BigDecimal)

Example 45 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MPPCostCollector method getCostCollectorNotTransaction.

/**
	 * get Cost Collector That not was generate by inventory transaction
	 * @param productId
	 * @param dateAccount
	 * @param dateAccountTo
	 * @param trxName
	 * @return Collection the Cost Collector
	 */
public static List<MPPCostCollector> getCostCollectorNotTransaction(Properties ctx, int productId, Timestamp dateAccount, Timestamp dateAccountTo, String trxName) {
    List<Object> params = new ArrayList();
    final StringBuffer whereClause = new StringBuffer();
    whereClause.append(MPPCostCollector.COLUMNNAME_CostCollectorType + " NOT IN ('100','110') AND ");
    if (productId > 0) {
        whereClause.append(MPPCostCollector.COLUMNNAME_M_Product_ID + "=? AND ");
        params.add(productId);
    }
    if (dateAccount == null || dateAccountTo == null)
        throw new AdempiereException("@DateAcct@ @NotFound@");
    whereClause.append(MPPCostCollector.COLUMNNAME_DateAcct + ">=? AND ");
    params.add(dateAccount);
    whereClause.append(MPPCostCollector.COLUMNNAME_DateAcct + "<=?");
    params.add(dateAccountTo);
    return new Query(ctx, I_PP_Cost_Collector.Table_Name, whereClause.toString(), trxName).setClient_ID().setParameters(params).list();
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)216 BigDecimal (java.math.BigDecimal)64 SQLException (java.sql.SQLException)42 ResultSet (java.sql.ResultSet)29 PreparedStatement (java.sql.PreparedStatement)28 MProduct (org.compiere.model.MProduct)28 ArrayList (java.util.ArrayList)27 Timestamp (java.sql.Timestamp)23 Query (org.compiere.model.Query)19 PO (org.compiere.model.PO)16 MBPartner (org.compiere.model.MBPartner)14 Properties (java.util.Properties)13 File (java.io.File)12 List (java.util.List)12 ProcessInfo (org.compiere.process.ProcessInfo)12 Arrays (java.util.Arrays)10 Env (org.compiere.util.Env)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 MMovement (org.compiere.model.MMovement)9 Date (java.util.Date)8