Search in sources :

Example 1 with TrxRunnable

use of org.compiere.util.TrxRunnable in project adempiere by adempiere.

the class VCreateFromPanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
        try {
            Trx.run(new TrxRunnable() {

                public void run(String trxName) {
                    if (save(trxName)) {
                        createFrom.dispose();
                    }
                }
            });
        } catch (Exception ex) {
            ADialog.error(createFrom.getWindowNo(), this, "Error", ex.getLocalizedMessage());
        }
    } else //  Cancel
    if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
        createFrom.dispose();
    } else // Trifon
    if (e.getActionCommand().equals(SELECT_ALL)) {
        dataTable.selectAll();
        dataTable.matchCheckWithSelectedRows();
        info();
    }
}
Also used : TrxRunnable(org.compiere.util.TrxRunnable)

Example 2 with TrxRunnable

use of org.compiere.util.TrxRunnable in project adempiere by adempiere.

the class WCreateFromWindow method onEvent.

public void onEvent(Event e) throws Exception {
    //  OK - Save
    if (e.getTarget().getId().equals(ConfirmPanel.A_OK)) {
        try {
            Trx.run(new TrxRunnable() {

                public void run(String trxName) {
                    if (save(trxName)) {
                        dispose();
                    }
                }
            });
        } catch (Exception ex) {
            FDialog.error(windowNo, this, "Error", ex.getLocalizedMessage());
        }
    } else //  Cancel
    if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    } else // Trifon
    if (e.getTarget().getId().equals(SELECT_ALL)) {
        ListModelTable model = dataTable.getModel();
        int rows = model.getSize();
        for (int i = 0; i < rows; i++) {
            model.setValueAt(new Boolean(true), i, 0);
        }
        //refresh
        dataTable.setModel(model);
        info();
    }
}
Also used : ListModelTable(org.adempiere.webui.component.ListModelTable) TrxRunnable(org.compiere.util.TrxRunnable)

Example 3 with TrxRunnable

use of org.compiere.util.TrxRunnable in project adempiere by adempiere.

the class VPayment method saveChanges.

//	actionPerformed
/**************************************************************************
	 *	Save Changes
	 *	@return true, if Window can exit
	 */
private boolean saveChanges() {
    // BF [ 1920179 ] perform the save in a trx's context.
    final boolean[] success = new boolean[] { false };
    final TrxRunnable r = new TrxRunnable() {

        public void run(String trxName) {
            success[0] = saveChangesInTrx(trxName);
        }
    };
    try {
        Trx.run(r);
    } catch (Throwable e) {
        success[0] = false;
        ADialog.error(m_WindowNo, this, "PaymentError", e.getLocalizedMessage());
    }
    if (m_cashLine != null)
        m_cashLine.set_TrxName(null);
    if (m_mPayment != null)
        m_mPayment.set_TrxName(null);
    if (m_mPaymentOriginal != null)
        m_mPayment.set_TrxName(null);
    return success[0];
}
Also used : TrxRunnable(org.compiere.util.TrxRunnable)

Example 4 with TrxRunnable

use of org.compiere.util.TrxRunnable in project adempiere by adempiere.

the class VCreateFromDialog method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
        try {
            Trx.run(new TrxRunnable() {

                public void run(String trxName) {
                    if (save(trxName)) {
                        dispose();
                    }
                }
            });
        } catch (Exception ex) {
            ADialog.error(windowNo, this, "Error", ex.getLocalizedMessage());
        }
    } else //  Cancel
    if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    } else // Trifon
    if (e.getActionCommand().equals(SELECT_ALL)) {
        dataTable.selectAll();
        dataTable.matchCheckWithSelectedRows();
        info();
    }
}
Also used : TrxRunnable(org.compiere.util.TrxRunnable)

Example 5 with TrxRunnable

use of org.compiere.util.TrxRunnable in project adempiere by adempiere.

the class RollupWorkflow method doIt.

//	prepare
protected String doIt() throws Exception {
    //Get account schema
    MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    //Get cost type
    MCostType costType = MCostType.get(getCtx(), getCostTypeId());
    //Get cost element to process
    final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
    routingService = RoutingServiceFactory.get().getRoutingService(getAD_Client_ID());
    //Iterate product ids based on parameters
    Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
        MProduct product = MProduct.get(getCtx(), productId);
        log.info("Product: " + product);
        int workflowId = 0;
        MPPProductPlanning productPlanning = null;
        if (workflowId <= 0)
            workflowId = MWorkflow.getWorkflowSearchKey(product);
        if (workflowId <= 0) {
            productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), product.get_ID(), get_TrxName());
            if (productPlanning != null)
                workflowId = productPlanning.getAD_Workflow_ID();
            else
                createNotice(product, "@NotFound@ @PP_Product_Planning_ID@");
        }
        if (workflowId <= 0)
            createNotice(product, "@NotFound@ @AD_Workflow_ID@");
        else {
            Trx.run(new TrxRunnable() {

                MAcctSchema accountSchema;

                MCostType costType;

                MProduct product;

                MPPProductPlanning productPlanning;

                int workflowId;

                public TrxRunnable setParameters(MAcctSchema accountSchema, MCostType costType, MProduct product, MPPProductPlanning productPlanning, int workflowId) {
                    this.accountSchema = accountSchema;
                    this.costType = costType;
                    this.product = product;
                    this.productPlanning = productPlanning;
                    this.workflowId = workflowId;
                    return this;
                }

                public void run(String trxName) {
                    MWorkflow workflow = new MWorkflow(getCtx(), workflowId, trxName);
                    costElements.stream().filter(costElement -> costElement != null && CostEngine.isActivityControlElement(costElement)).forEach(costElement -> {
                        rollup(accountSchema, costType, costElement, product, workflow, trxName);
                    });
                    if (productPlanning != null) {
                        productPlanning.load(trxName);
                        productPlanning.setYield(workflow.getYield());
                        productPlanning.saveEx();
                    }
                }
            }.setParameters(accountSchema, costType, product, productPlanning, workflowId));
        }
    });
    return "@OK@";
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Arrays(java.util.Arrays) Env(org.compiere.util.Env) MCostType(org.compiere.model.MCostType) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) RoutingService(org.eevolution.model.RoutingService) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) Msg(org.compiere.util.Msg) Trx(org.compiere.util.Trx) CostEngine(org.adempiere.engine.CostEngine) RoundingMode(java.math.RoundingMode) CostEngineFactory(org.adempiere.engine.CostEngineFactory) CostDimension(org.adempiere.engine.CostDimension) MWorkflow(org.compiere.wf.MWorkflow) StandardCostingMethod(org.adempiere.engine.StandardCostingMethod) RoutingServiceFactory(org.eevolution.model.RoutingServiceFactory) List(java.util.List) MWFNode(org.compiere.wf.MWFNode) MCostElement(org.compiere.model.MCostElement) TrxRunnable(org.compiere.util.TrxRunnable) MProduct(org.compiere.model.MProduct) MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MWorkflow(org.compiere.wf.MWorkflow) TrxRunnable(org.compiere.util.TrxRunnable) MCostType(org.compiere.model.MCostType)

Aggregations

TrxRunnable (org.compiere.util.TrxRunnable)12 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MProduct (org.compiere.model.MProduct)3 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ListModelTable (org.adempiere.webui.component.ListModelTable)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MCost (org.compiere.model.MCost)2 MCostElement (org.compiere.model.MCostElement)2 MCostType (org.compiere.model.MCostType)2 Query (org.compiere.model.Query)2 Env (org.compiere.util.Env)2 Msg (org.compiere.util.Msg)2 Trx (org.compiere.util.Trx)2 MWorkflow (org.compiere.wf.MWorkflow)2 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)2 IOException (java.io.IOException)1