Package org.salamanca.commands.vale

Source Code of org.salamanca.commands.vale.DeshacerUtilizacion

package org.salamanca.commands.vale;

import java.util.Date;
import org.salamanca.domain.Vale;
import javax.jdo.PersistenceManager;
import org.salamanca.broker.BrokerServer;
import org.salamanca.commands.MessageException;
import org.salamanca.commands.ICommand;
import java.util.Calendar;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class DeshacerUtilizacion implements ICommand {


    Vale vale;


    public DeshacerUtilizacion(Vale vale) {
        this.vale = vale;

    }


    /**
     * execute
     */
    public void execute() throws MessageException {

        Date fechaYa = new Date();

        if (vale.getFechaUtilizacion() != null) {
            Calendar calYa = Calendar.getInstance();
            calYa.setTime(fechaYa);
            Calendar calUtil = Calendar.getInstance();
            calUtil.setTime(vale.getFechaUtilizacion());

            if (calYa.get(Calendar.DAY_OF_YEAR) !=
                calUtil.get(Calendar.DAY_OF_YEAR)) {
                throw new MessageException(
                        "Los vales solo se pueden deshacer el mismo dia que fueron utilizados");
            }

        }

        PersistenceManager pm = BrokerServer.instance().getPMF().
                                getPersistenceManager();

        pm.currentTransaction().begin();

        Vale valePM = (Vale) pm.getObjectById(javax.jdo.JDOHelper.
                                              getObjectId(
                vale), true);

        valePM.setFechaUtilizacion(null);

        pm.currentTransaction().commit();

    }

    /**
     * getCommandName
     *
     * @return String
     */
    public String getCommandName() {
        return this.getClass().getName();
    }

    /**
     * getBarDelimitedParameters
     *
     * @return String
     */
    public String getBarDelimitedParameters() {
        return vale.getPersona().getNombre() + "|" + vale.getImporte() + "|" +
                vale.getFechaEmision();
    }


}
TOP

Related Classes of org.salamanca.commands.vale.DeshacerUtilizacion

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.