Search in sources :

Example 11 with MPInstance

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

the class WProcess method fillParameter.

/**
	 * 	Fill Parameter
	 *	@param request request
	 *	@param process process
	 *	@return process instance
	 */
private MPInstance fillParameter(HttpServletRequest request, MProcess process) {
    MPInstance pInstance = new MPInstance(process, 0);
    //
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        String valueString = MobileUtil.getParameter(request, key);
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        //	No Value
        if (value == null) {
        //	if (pPara.isMandatory())
        //		log.log(Level.WARNING,"fillParameter - " + key 
        //			+ " - empty - mandatory!");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(pPara.getAD_Reference_ID()) || DisplayType.isID(pPara.getAD_Reference_ID())) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                } else if (DisplayType.isDate(pPara.getAD_Reference_ID())) {
                    Timestamp ts = null;
                    if (value instanceof Timestamp)
                        ts = (Timestamp) value;
                    else
                        ts = Timestamp.valueOf(value.toString());
                    iPara.setP_Date(ts);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else {
                    if (pPara.getAD_Reference_ID() == DisplayType.YesNo)
                        value = "true".equalsIgnoreCase(value.toString()) ? "Y" : "N";
                    iPara.setP_String(value.toString());
                }
                //
                iPara.saveEx();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 12 with MPInstance

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

the class ProcessController method updateInstance.

/**
	 * Update a instance from Name
	 * @param saveName
	 * @return
	 */
public String updateInstance(String saveName) {
    //	Validate Instance List
    if (savedParams == null || saveName == null)
        return null;
    //	
    String errorMsg = null;
    try {
        for (MPInstance instance : savedParams) {
            if (instance.getName().equals(saveName)) {
                processInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
                for (MPInstancePara para : instance.getParameters()) {
                    para.deleteEx(true);
                }
                //	Save
                errorMsg = saveParameters();
                if (errorMsg != null)
                    throw new AdempiereException(errorMsg);
            }
        }
    } catch (Exception ex) {
        errorMsg = ex.getLocalizedMessage();
        log.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    //	Default Return
    return errorMsg;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) AdempiereException(org.adempiere.exceptions.AdempiereException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 13 with MPInstance

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

the class ProcessCtl method process.

/**
	 *	Process Control
	 *  <code>
	 *	- Get Instance ID
	 *	- Get Parameters
	 *	- execute (lock - start process - unlock)
	 *  </code>
	 *  Creates a ProcessCtl instance, which calls
	 *  lockUI and unlockUI if parent is a ASyncProcess
	 *  <br>
	 *	Called from APanel.cmd_print, APanel.actionButton and
	 *  VPaySelect.cmd_generate
	 *
	 *  @param parent ASyncProcess & Container
	 *  @param WindowNo window no
	 *  @param pi ProcessInfo process info
	 *  @param trx Transaction
	 *  @return worker started ProcessCtl instance or null for workflow
	 */
public static ProcessCtl process(ASyncProcess parent, int WindowNo, ProcessInfo pi, Trx trx) {
    log.fine("WindowNo=" + WindowNo + " - " + pi);
    MPInstance instance = null;
    try {
        instance = new MPInstance(Env.getCtx(), pi.getAD_Process_ID(), pi.getRecord_ID());
    } catch (Exception e) {
        pi.setSummary(e.getLocalizedMessage());
        pi.setError(true);
        log.warning(pi.toString());
        return null;
    } catch (Error e) {
        pi.setSummary(e.getLocalizedMessage());
        pi.setError(true);
        log.warning(pi.toString());
        return null;
    }
    if (!instance.save()) {
        pi.setSummary(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        pi.setError(true);
        return null;
    }
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Get Parameters (Dialog)
    //	FR [ 265 ]
    //	Change to Standard Process Modal Dialog
    ProcessModalDialog para = new ProcessModalDialog(Env.getFrame((Container) parent), WindowNo, pi);
    if (para.isValidDialog()) {
        para.validate();
        para.pack();
        AEnv.showCenterWindow(Env.getWindow(WindowNo), para);
        if (!para.isOK()) {
            return null;
        }
    }
    //	execute
    ProcessCtl worker = new ProcessCtl(parent, WindowNo, pi, trx);
    if (parent != null) {
        //asynchrous
        worker.start();
    } else {
        //synchrous
        worker.run();
    }
    return worker;
}
Also used : MPInstance(org.compiere.model.MPInstance) Container(java.awt.Container) InvalidClassException(java.io.InvalidClassException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 14 with MPInstance

use of org.compiere.model.MPInstance in project lar_361 by comitsrl.

the class LAR_Validator method anularOperación.

// Marcos Zúñiga -end
/**
 * Anular toda la operación de venta (OV - Recibos - Factura y Remito).
 *
 * @param invoice
 */
private void anularOperación(final MInvoice invoice, final String documentNo, final String fiscalreceiptnumber) {
    SwingWorker worker = new SwingWorker() {

        private String errorMsg = null;

        @Override
        public Object construct() {
            // Crea parámetro que se enviará al proceso
            final ProcessInfoParameter param = new ProcessInfoParameter("C_Order_ID", invoice.getC_Order_ID(), "", "", "");
            // Crea información del proceso
            int AD_Process_ID = 3000037;
            final ProcessInfo pi = new ProcessInfo("PosOrderGlobalVoiding", AD_Process_ID);
            pi.setParameter(new ProcessInfoParameter[] { param });
            // Crea una instancia de proceso (para registro y
            // sincronizacion)
            final MPInstance pinstance = new MPInstance(Env.getCtx(), 0, null);
            pinstance.setAD_Process_ID(AD_Process_ID);
            pinstance.setRecord_ID(0);
            pinstance.save();
            // Conecta el proceso con la instancia de proceso
            pi.setAD_PInstance_ID(pinstance.get_ID());
            // Crea el proceso a ejecutar
            final PosOrderGlobalVoiding process = new PosOrderGlobalVoiding();
            log.info("Iniciando proceso global de anulaci\u00f3n");
            return process.startProcess(Env.getCtx(), pi, null);
        }

        // construct
        @Override
        public void finished() {
            boolean success = (Boolean) getValue();
            if (!success) {
                ADialog.error(0, Env.getWindow(0), errorMsg);
            } else {
                ADialog.warn(0, Env.getWindow(0), "Número de Documento " + documentNo + " duplicado.", "Operación anulada.");
                // Corregir Secuencia.
                MSequence.setFiscalDocTypeNextNroComprobante(invoice.getC_DocType().getDefiniteSequence_ID(), Integer.parseInt(fiscalreceiptnumber) + 1, null);
            }
        }
    };
    // new SwingWorker
    worker.start();
    worker.finished();
}
Also used : ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) PosOrderGlobalVoiding(ar.com.ergio.process.PosOrderGlobalVoiding) MPInstance(org.compiere.model.MPInstance) SwingWorker(org.compiere.apps.SwingWorker) ProcessInfo(org.compiere.process.ProcessInfo)

Example 15 with MPInstance

use of org.compiere.model.MPInstance in project lar_361 by comitsrl.

the class LAR_Callouts method copyLines.

/**
 * Callout used in Source_Invoice_ID field (C_Invoice table), in order to copy
 * lines of source invoice
 */
public String copyLines(final Properties ctx, final int windowNo, final GridTab mTab, final GridField mField, Object value) throws AdempiereSystemError {
    Integer Source_Invoice_ID = (Integer) value;
    if (Source_Invoice_ID == null || Source_Invoice_ID.intValue() == 0)
        return "";
    if (!ADialog.ask(windowNo, Env.getWindow(windowNo), "¿Copiar las líneas desde la Factura?"))
        return "";
    // Config CopyFromInvoice process (AD_Process_ID=210)
    int AD_Process_ID = 210;
    int C_Invoice_ID = (Integer) mTab.getValue("C_Invoice_ID");
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save())
        return Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
    ProcessInfo pi = new ProcessInfo("", AD_Process_ID);
    pi.setRecord_ID(C_Invoice_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    // Add Parameters
    MPInstancePara param = new MPInstancePara(instance, 10);
    param.setParameter("C_Invoice_ID", Source_Invoice_ID);
    if (!param.save())
        return Msg.getMsg(Env.getCtx(), "ParameterMissing");
    // TODO - Creates a dummy asyc control process thread (review)
    final ASyncProcess asyncProcess = new ASyncProcess() {

        private JFrame component = Env.getWindow(windowNo);

        /**
         * {@inheritDoc}
         */
        public void lockUI(ProcessInfo pi) {
            component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            component.setEnabled(false);
        }

        // lockUI
        /**
         * {@inheritDoc}
         */
        public void unlockUI(ProcessInfo pi) {
            component.setEnabled(true);
            component.setCursor(Cursor.getDefaultCursor());
        }

        // unlockUI
        /**
         * {@inheritDoc}
         */
        public boolean isUILocked() {
            return component.isEnabled();
        }

        // isUILocked
        /**
         * {@inheritDoc}
         */
        public void executeASync(ProcessInfo pi) {
        }
    };
    // Execute process
    ProcessCtl worker = new ProcessCtl(asyncProcess, windowNo, pi, null);
    worker.run();
    return "";
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) JFrame(javax.swing.JFrame) ProcessCtl(org.compiere.apps.ProcessCtl) ASyncProcess(org.compiere.util.ASyncProcess) ProcessInfo(org.compiere.process.ProcessInfo)

Aggregations

MPInstance (org.compiere.model.MPInstance)37 ProcessInfo (org.compiere.process.ProcessInfo)21 MPInstancePara (org.compiere.model.MPInstancePara)19 Trx (org.compiere.util.Trx)12 SQLException (java.sql.SQLException)8 Timestamp (java.sql.Timestamp)8 File (java.io.File)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 MProcess (org.compiere.model.MProcess)7 IOException (java.io.IOException)6 ReportEngine (org.compiere.print.ReportEngine)6 BigDecimal (java.math.BigDecimal)4 ServletException (javax.servlet.ServletException)4 InvalidClassException (java.io.InvalidClassException)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 ProcessCtl (org.compiere.apps.ProcessCtl)3 MProcessPara (org.compiere.model.MProcessPara)3 ProcessInfoParameter (org.compiere.process.ProcessInfoParameter)3 PosOrderGlobalVoiding (ar.com.ergio.process.PosOrderGlobalVoiding)2