/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sikd.ikonsol.ctrl;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.PrimeFaces;
import sikd.ikonsol.ejb.session.JenisTransferEjbHome;
import sikd.ikonsol.model.JenisTransfer;

/**
 *
 * @author Imam Bhoim
 */
@ViewScoped
@Named(value = "jenisTransferBeanCtrl")
public class JenisTransferBeanCtrl implements Serializable {

    JenisTransfer jtransfer;
    JenisTransfer obj;
    private List<JenisTransfer> list;

    private int id;
    private String nama;

    @EJB
    JenisTransferEjbHome jtransferEjbHome;

    @PostConstruct
    public void init() {
        try {
            list = jtransferEjbHome.findAll();
        } catch (Exception e) {
            e.printStackTrace();
        }

        //obj = periodeEjbHome.findByKode("22");
        //periode = periodeEjbHome.createNew();
    }

    public void add() {

        jtransfer = jtransferEjbHome.createNew();

    }

    public String save() {

        // simpan
        jtransferEjbHome.save(jtransfer);

        PrimeFaces.current().executeScript("PF('wg_entryform').hide()");
        PrimeFaces.current().ajax().update(":master:dtjtransfer");

        list = jtransferEjbHome.findAll();
        //this.list = service.findAll();
        return "index?faces-redirect=true";
    }

    public String update() {

        jtransferEjbHome.update(obj);

        PrimeFaces.current().executeScript("PF('wg_entryform_ubah').hide()");
        PrimeFaces.current().ajax().update(":master:dtjtransfer");

        list = jtransferEjbHome.findAll();
        // this.list = service.findAll();
        return "index?faces-redirect=true";
    }

    public void edit(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        obj = jtransferEjbHome.findByID(id);

    }

    public void delete(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        //obj = periodeEjbHome.findByKode(kode);
        jtransferEjbHome.delete(id);
        PrimeFaces.current().ajax().update(":master:dtjtransfer");
        list = jtransferEjbHome.findAll();
    }

    public JenisTransfer getJtransfer() {
        return jtransfer;
    }

    public void setJtransfer(JenisTransfer jtransfer) {
        this.jtransfer = jtransfer;
    }

    public JenisTransfer getObj() {
        return obj;
    }

    public void setObj(JenisTransfer obj) {
        this.obj = obj;
    }

    public List<JenisTransfer> getList() {
        return list;
    }

    public void setList(List<JenisTransfer> list) {
        this.list = list;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public JenisTransferEjbHome getJtransferEjbHome() {
        return jtransferEjbHome;
    }

    public void setJtransferEjbHome(JenisTransferEjbHome jtransferEjbHome) {
        this.jtransferEjbHome = jtransferEjbHome;
    }

}
