/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.gui.controladores.seguridad;

import com.rjconsultores.ventaboletos.entidad.CompaniaBancaria;
import com.rjconsultores.ventaboletos.entidad.MerchantBancario;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;
import java.util.Calendar;
import java.util.List;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.util.resource.Labels;
import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;

/**
 *
 * @author Administrador
 */
@Controller("editarMerchantBancarioController")
@Scope("prototype")
public class EditarMerchantBancarioController extends MyGenericForwardComposer {

    private CompaniaBancaria companiaBancaria;
    private MerchantBancario merchantBancario;
    private List<MerchantBancario> lsMerchantBancario;
    private MyListbox merchantBancarioList;

    public MerchantBancario getMerchantBancario() {
        return merchantBancario;
    }

    public void setMerchantBancario(MerchantBancario merchantBancario) {
        this.merchantBancario = merchantBancario;
    }

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);

        companiaBancaria = (CompaniaBancaria) Executions.getCurrent().getArg().get("companiaBancaria");
        merchantBancarioList = (MyListbox) Executions.getCurrent().getArg().get("merchantBancarioList");
        lsMerchantBancario = (List) Executions.getCurrent().getArg().get("lsMerchantBancario");

        merchantBancario = new MerchantBancario();
        merchantBancario.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
        merchantBancario.setActivo(Boolean.TRUE);
        merchantBancario.setFecmodif(Calendar.getInstance().getTime());
        merchantBancario.setCompaniaBancaria(companiaBancaria);
    }

    public void onClick$btnSalvar(Event ev) throws InterruptedException {

        for (MerchantBancario ub : lsMerchantBancario) {
            if (ub.getCvemerchant().equals(merchantBancario.getCvemerchant())) {
                Messagebox.show(
                        Labels.getLabel("MSG.Registro.Existe"),
                        Labels.getLabel("editarMerchantBancarioController.window.title"),
                        Messagebox.OK, Messagebox.EXCLAMATION);

                return;
            }
        }

        lsMerchantBancario.add(merchantBancario);
        merchantBancarioList.setData(lsMerchantBancario);
        closeWindow();
    }
}
