Package org.salamanca.commands.pago

Source Code of org.salamanca.commands.pago.AnularPago

package org.salamanca.commands.pago;

import org.salamanca.commands.ICommand;
import org.salamanca.domain.Pago;
import java.util.Iterator;
import org.salamanca.domain.CuotaBasica;
import org.salamanca.broker.BrokerServer;
import javax.jdo.PersistenceManager;
import org.salamanca.commands.MessageException;
import org.salamanca.domain.Alumno;
import java.util.*;

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

    Pago pago = null;
    Alumno alumno;
    CuotaBasica cuotaBasica;


    public AnularPago(Alumno alumno, CuotaBasica cuotaBasica) {

        this.alumno = alumno;
        this.cuotaBasica = cuotaBasica;

        Iterator iter = this.alumno.getSetPagos().iterator();
        while (iter.hasNext()) {
            Pago itemPago = (Pago) iter.next();
            //si esa cuota fue pagada y no anulada obtengo el objeto "Pago"
            if (!itemPago.isAnulado()) {
                if (javax.jdo.JDOHelper.getObjectId(itemPago.getCuotaPagada()).
                    equals(javax.jdo.JDOHelper.getObjectId(this.cuotaBasica))) {
                    this.pago = itemPago;
                }
            }
        }

    }


    /**
     * execute
     */
    public void execute() throws MessageException {
        if (this.pago == null) {
            throw new MessageException(
                    "No existe el pago para anular!");
        }
        PersistenceManager pm = BrokerServer.instance().getPMF().
                                getPersistenceManager();
        pm.currentTransaction().begin();
        Pago pagoPM = (Pago) pm.getObjectById(javax.jdo.
                                              JDOHelper.
                                              getObjectId(pago),true);

        pagoPM.setAnulado(true);
        pagoPM.setFechaAnulacion(new Date());
        pm.currentTransaction().commit();

    }


//v.size() == 0 ||
    /**
     * getCommandName
     *
     * @return String
     */
    public String getCommandName() {
        return this.getClass().getName();
    }

    /**
     * getBarDelimitedParameters
     *
     * @return String
     */
    public String getBarDelimitedParameters() {
        if (pago != null) {
            return pago.getCuotaPagada().getConcepto() + "|" +
                    pago.getCuotaPagada().getCurso().getNombre() + "|" +
                    pago.getAlumno().getDocumento() + "|" +
                    pago.getNombreDescuento() + "|" + pago.getImportePagado();
        } else {
            return "invalido";
        }
    }

}
TOP

Related Classes of org.salamanca.commands.pago.AnularPago

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.