Search in sources :

Example 31 with AdempiereException

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

the class ReleaseInOutBound method doIt.

/**
	 * 	Process - Generate Export Format
	 *	@return info
	 */
@Override
protected String doIt() throws Exception {
    List<MWMInOutBoundLine> outBoundLines = (List<MWMInOutBoundLine>) getInstancesForSelection(get_TrxName());
    outBoundLines.stream().forEach(outBoundLine -> {
        if (outBoundLine.getDD_OrderLine_ID() > 0) {
            MDDOrderLine orderDistributionLine = (MDDOrderLine) outBoundLine.getDD_OrderLine();
            if (orderDistributionLine.getWM_InOutBoundLine_ID() <= 0) {
                orderDistributionLine.setWM_InOutBoundLine_ID(orderDistributionLine.getWM_InOutBoundLine_ID());
                orderDistributionLine.saveEx();
            }
            if (orderDistributionLine.getM_LocatorTo_ID() == outBoundLocator.getM_Locator_ID())
                return;
        }
        BigDecimal qtySupply = createDistributionOrder(outBoundLine);
        if (isCreateSupply() && qtySupply.signum() > 0) {
            Env.setContext(outBoundLine.getCtx(), IsCreateSupply, "Y");
            createSupply(outBoundLine, qtySupply);
        }
    });
    if (orderDistribution != null && getDocumentAction() != null) {
        orderDistribution.setDocAction(getDocumentAction());
        orderDistribution.setDocStatus(org.compiere.process.DocAction.STATUS_InProgress);
        orderDistribution.completeIt();
        orderDistribution.save();
    }
    if (isPrintPickList() && orderDistribution != null) {
        // Get Format & Data
        ReportEngine reportEngine = getReportEngine("DistributionOrder_Header  ** TEMPLATE **", "DD_Order_Header_v", orderDistribution.getDD_Order_ID());
        if (reportEngine == null)
            throw new AdempiereException("@NotFound@ @AD_PrintFormat_ID@");
        ReportCtl.preview(reportEngine);
        // prints only original
        reportEngine.print();
    }
    //@DocumentNo@ " + order.getDocumentNo();
    return "";
}
Also used : MWMInOutBoundLine(org.eevolution.model.MWMInOutBoundLine) MDDOrderLine(org.eevolution.model.MDDOrderLine) ReportEngine(org.compiere.print.ReportEngine) AdempiereException(org.adempiere.exceptions.AdempiereException) List(java.util.List) BigDecimal(java.math.BigDecimal)

Example 32 with AdempiereException

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

the class GenerateShipmentOutBound method processingMovements.

public void processingMovements() {
    distributionOrders.entrySet().stream().forEach(entry -> {
        I_DD_Order distributionOrder = entry.getValue();
        List<Integer> orderIds = new ArrayList<Integer>();
        orderIds.add(distributionOrder.getDD_Order_ID());
        ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(MovementGenerate.getProcessId()).withSelectedRecordsIds(orderIds).withParameter(MWMInOutBound.COLUMNNAME_M_Warehouse_ID, distributionOrder.getM_Warehouse_ID()).withParameter(MMovement.COLUMNNAME_MovementDate, getMovementDate()).withoutTransactionClose().execute(get_TrxName());
        if (processInfo.isError())
            throw new AdempiereException(processInfo.getSummary());
        addLog(processInfo.getSummary());
        Arrays.stream(processInfo.getIDs()).forEach(recordId -> {
            MMovement movement = new MMovement(getCtx(), recordId, get_TrxName());
            if (movement != null && movement.get_ID() > 0)
                GenerateMovement.printDocument(movement, "Inventory Move Hdr (Example)", processInfo.getWindowNo());
            else
                throw new AdempiereException("@M_Movement_ID@ @NotFound@");
        });
    });
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) I_DD_Order(org.eevolution.model.I_DD_Order) MMovement(org.compiere.model.MMovement)

Example 33 with AdempiereException

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

the class WMRuleEngine method applyDefinition.

/**
	 * Apply Definition for Warehouse  Strategy
	 * @param inOutBoundLine Order Bound Line
	 * @param warehouseAreaTypeId Area Type Id
	 * @param warehouseSectionTypeId Section Type Id
	 * */
private MWMStrategy applyDefinition(MWMInOutBoundLine inOutBoundLine, int warehouseAreaTypeId, int warehouseSectionTypeId) {
    StringBuffer whereClause = new StringBuffer("(");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IS NULL");
    whereClause.append(")");
    whereClause.append(" AND EXISTS (SELECT 1 FROM " + MWMStrategy.Table_Name);
    whereClause.append(" WHERE ");
    whereClause.append(MWMStrategy.Table_Name + "." + MWMStrategy.COLUMNNAME_WM_Strategy_ID + "=");
    whereClause.append(MWMDefinition.Table_Name + "." + MWMDefinition.COLUMNNAME_WM_Strategy_ID);
    whereClause.append(" AND ");
    whereClause.append(MWMStrategy.COLUMNNAME_InOutBoundType + "=?");
    whereClause.append(")");
    MProduct product = inOutBoundLine.getMProduct();
    MBPartner partner = inOutBoundLine.getBPartner();
    MWMDefinition definition = new Query(inOutBoundLine.getCtx(), MWMDefinition.Table_Name, whereClause.toString(), inOutBoundLine.get_TrxName()).setClient_ID().setParameters(product.getM_Product_ID(), product.getM_Product_Category_ID(), product.getGroup1(), product.getGroup2(), product.getClassification(), partner.getC_BPartner_ID(), partner.getC_BP_Group_ID(), warehouseAreaTypeId, warehouseSectionTypeId, MWMStrategy.INOUTBOUNDTYPE_OutboundOperation).first();
    if (definition == null) {
        throw new AdempiereException("@WM_Definition_ID@ @NotFound@");
    }
    return definition.getWarehouseStrategy();
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) MWMDefinition(org.eevolution.model.MWMDefinition) MBPartner(org.compiere.model.MBPartner)

Example 34 with AdempiereException

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

the class GridTabDataBinder method valueChange.

/**
	 * @param e
	 */
public void valueChange(ValueChangeEvent e) {
    if (//  only active records
    gridTab.isProcessed()) {
        Object source = e.getSource();
        if (source instanceof WEditor) {
            // Elaine 2009/05/06
            WEditor editor = (WEditor) source;
            GridField gridField = editor.getGridField();
            if (gridField != null) {
                if (!gridField.isEditable(true)) {
                    logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
                    return;
                }
            } else if (!editor.isReadWrite()) {
                logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
                return;
            }
        } else {
            logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
            return;
        }
    }
    //  processed
    logger.config("(" + gridTab.toString() + ") " + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));
    //  Get Row/Col Info
    GridTable mTable = gridTab.getTableModel();
    int row = gridTab.getCurrentRow();
    int col = mTable.findColumn(e.getPropertyName());
    //
    if (e.getNewValue() == null && e.getOldValue() != null && //  some editors return "" instead of null
    e.getOldValue().toString().length() > 0)
        //        	  this is the original code from GridController, don't know what it does there but it breaks ignore button for web ui        
        //            mTable.setChanged (true);  
        mTable.setValueAt(e.getNewValue(), row, col);
    else {
        Object newValue = e.getNewValue();
        Integer[] newValues = null;
        if (newValue instanceof Integer[]) {
            newValues = ((Integer[]) newValue);
            newValue = newValues[0];
            if (newValues.length > 1) {
                Integer[] valuesCopy = new Integer[newValues.length - 1];
                System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
                newValues = valuesCopy;
            } else {
                newValues = null;
            }
        } else if (newValue instanceof Object[]) {
            logger.severe("Multiple values can only be processed for IDs (Integer)");
            throw new IllegalArgumentException("Multiple Selection values not available for this field. " + e.getPropertyName());
        }
        mTable.setValueAt(newValue, row, col);
        //  Force Callout
        if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
            GridField mField = gridTab.getField(col);
            if (mField != null && mField.getCallout().length() > 0) {
                //  Dependencies & Callout
                gridTab.processFieldChange(mField);
            }
        }
        if (newValues != null && newValues.length > 0) {
            // Save data, since record need to be used for generating clones.
            if (!gridTab.dataSave(false)) {
                throw new AdempiereException("SaveError");
            }
            // Retrieve the current record ID
            int recordId = gridTab.getKeyID(gridTab.getCurrentRow());
            Trx trx = Trx.get(Trx.createTrxName(), true);
            trx.start();
            try {
                saveMultipleRecords(Env.getCtx(), gridTab.getTableName(), e.getPropertyName(), recordId, newValues, trx.getTrxName());
                trx.commit();
                gridTab.dataRefreshAll();
            } catch (Exception ex) {
                trx.rollback();
                logger.severe(ex.getMessage());
                throw new AdempiereException("SaveError");
            } finally {
                trx.close();
            }
        }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) GridTable(org.compiere.model.GridTable) WEditor(org.adempiere.webui.editor.WEditor) GridField(org.compiere.model.GridField) Trx(org.compiere.util.Trx) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 35 with AdempiereException

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

the class ServerPushTemplate method execute.

/**
	 * Execute callback in UI thread
	 * @param callback
	 */
public void execute(IServerPushCallback callback) {
    boolean inUIThread = Executions.getCurrent() != null;
    boolean desktopActivated = false;
    try {
        if (!inUIThread) {
            //10 minutes timeout
            if (Executions.activate(desktop, 10 * 60 * 1000)) {
                desktopActivated = true;
            } else {
                throw new DesktopUnavailableException("Timeout activating desktop.");
            }
        }
        callback.updateUI();
    } catch (DesktopUnavailableException de) {
        throw de;
    } catch (Exception e) {
        throw new AdempiereException("Failed to update client in server push worker thread.", e);
    } finally {
        if (!inUIThread && desktopActivated) {
            Executions.deactivate(desktop);
        }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) DesktopUnavailableException(org.zkoss.zk.ui.DesktopUnavailableException) AdempiereException(org.adempiere.exceptions.AdempiereException) DesktopUnavailableException(org.zkoss.zk.ui.DesktopUnavailableException)

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